I believe you need to change this line.
-const document = titleText || "New project";
+const document = titleText.toString() || "New project";
I believe you need to change this line.
-const document = titleText || "New project";
+const document = titleText.toString() || "New project";