Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type number (55) #109

Open
gh-giant opened this issue Mar 13, 2024 · 0 comments

Comments

@gh-giant
Copy link

Hi everyone,

I wanted to output my inspection in a folder named after an ID, but I alwyas got an error: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type number (55).

That's why I have changed some files and I hope you agree with the changes.

Here is my git diff output.

diff --git a/collector/browser-session.js b/collector/browser-session.js
index 074c554..a87801c 100644
--- a/collector/browser-session.js
+++ b/collector/browser-session.js
@@ -42,7 +42,7 @@ async function createBrowserSession(browser_args, browser_logger) {
     userDataDir: args.browserProfile
       ? args.browserProfile
       : args.output
-      ? path.join(args.output, "browser-profile")
+      ? path.join(String(args.output), "browser-profile")
       : undefined,
     args: [
       `--user-agent=${UserAgent}`,
@@ -142,7 +142,7 @@ async function createBrowserSession(browser_args, browser_logger) {
     har = new PuppeteerHar(page);
 
     await har.start({
-      path: args.output ? path.join(args.output, "requests.har") : undefined,
+      path: args.output ? path.join(String(args.output), "requests.har") : undefined,
     });
 
     async function gotoPage(u) {
@@ -227,16 +227,16 @@ async function createBrowserSession(browser_args, browser_logger) {
       // record screenshots
       try {
         await page.screenshot({
-          path: path.join(args.output, "screenshot-top.png"),
+          path: path.join(String(args.output), "screenshot-top.png"),
         });
         await page.evaluate(() => {
           window.scrollTo(0, document.body.scrollHeight);
         });
         await page.screenshot({
-          path: path.join(args.output, "screenshot-bottom.png"),
+          path: path.join(String(args.output), "screenshot-bottom.png"),
         });
         await page.screenshot({
-          path: path.join(args.output, "screenshot-full.png"),
+          path: path.join(String(args.output), "screenshot-full.png"),
           fullPage: true,
         });
       } catch (error) {
diff --git a/collector/connection.js b/collector/connection.js
index f2421de..a0144dd 100644
--- a/collector/connection.js
+++ b/collector/connection.js
@@ -28,7 +28,7 @@ async function testSSL(uri, args, logger, output) {
     let json_file;
 
     if (args.output) {
-      let output_testssl = path.join(args.output, "testssl");
+      let output_testssl = path.join(String(args.output), "testssl");
       fs.mkdirSync(output_testssl);
 
       json_file = `${output_testssl}/testssl.json`;
diff --git a/collector/io.js b/collector/io.js
index 7a9540f..47e6bb0 100644
--- a/collector/io.js
+++ b/collector/io.js
@@ -2,22 +2,22 @@ const fs = require("fs-extra");
 
 function init(args) {
   // creating the folder structure - io
-  if (args.output) {
-    if (fs.existsSync(args.output)) {
-      if (fs.readdirSync(args.output).length > 0) {
+  if (String(args.output)) {
+    if (fs.existsSync(String(args.output))) {
+      if (fs.readdirSync(String(args.output)).length > 0) {
         if (args.overwrite) {
-          fs.emptyDirSync(args.output);
+          fs.emptyDirSync(String(String(args.output)));
         } else {
           console.error(
             "Error: Output folder or file " +
-              args.output +
+              String(args.output) +
               " is not empty. Delete/empty manually or call with --overwrite."
           );
           process.exit(1);
         }
       }
     } else {
-      fs.mkdirSync(args.output);
+      fs.mkdirSync(String(args.output));
     }
   }
 }
diff --git a/lib/logger.js b/lib/logger.js
index af37335..65ccada 100644
--- a/lib/logger.js
+++ b/lib/logger.js
@@ -58,7 +58,7 @@ const create = function (options, args = {}) {
   if (config.file.enabled) {
     let filename;
     if (args.output) {
-      filename = path.join(args.output, "inspection-log.ndjson");
+      filename = path.join(String(args.output), "inspection-log.ndjson");
     } else {
       filename = tmp.tmpNameSync({ postfix: "-log.ndjson" });
     }
diff --git a/reporter/index.js b/reporter/index.js
index bca28d9..457d18c 100644
--- a/reporter/index.js
+++ b/reporter/index.js
@@ -34,7 +34,7 @@ function reporter(args) {
     let json_dump = JSON.stringify(data, null, 2);
 
     if (c.args.output) {
-      fs.writeFileSync(path.join(c.args.output, filename), json_dump);
+      fs.writeFileSync(path.join(String(c.args.output), filename), json_dump);
     }
 
     if (log && c.args.json) {
@@ -46,7 +46,7 @@ function reporter(args) {
     let yaml_dump = yaml.dump(data, { noRefs: true });
 
     if (c.args.output) {
-      fs.writeFileSync(path.join(c.args.output, filename), yaml_dump);
+      fs.writeFileSync(path.join(String(c.args.output), filename), yaml_dump);
     }
 
     if (log && c.args.yaml) {
@@ -87,7 +87,7 @@ function reporter(args) {
     );
 
     if (c.args.output) {
-      fs.writeFileSync(path.join(c.args.output, filename), html_dump);
+      fs.writeFileSync(path.join(String(c.args.output), filename), html_dump);
     }
 
     if (log && c.args.html) {
@@ -102,9 +102,9 @@ function reporter(args) {
         headless: 'new',
       });
       const pages = await browser.pages();
-      await pages[0].goto("file://" + path.resolve(path.join(c.args.output, htmlfilename)), {waitUntil: 'networkidle0'});
+      await pages[0].goto("file://" + path.resolve(path.join(String(c.args.output), htmlfilename)), {waitUntil: 'networkidle0'});
       await pages[0].pdf({
-        path: path.resolve(path.join(c.args.output, pdffilename)),
+        path: path.resolve(path.join(String(c.args.output), pdffilename)),
         format: 'A4',
         printBackground: true,
         displayHeaderFooter: true,
@@ -181,14 +181,14 @@ function reporter(args) {
           creator: `EDPS Website Evidence Collector v${data.script.version.npm} using NPM html-to-docx`,
         };
         const fileBuffer = await HTMLtoDOCX(html_dump, null, documentOptions, null);
-        fs.writeFileSync(path.join(c.args.output, filename), fileBuffer);
+        fs.writeFileSync(path.join(String(c.args.output), filename), fileBuffer);
       }
     }
   };
 
   c.saveSource = function (source, filename = "source.html") {
     if (c.args.output) {
-      fs.writeFileSync(path.join(c.args.output, filename), source);
+      fs.writeFileSync(path.join(String(c.args.output), filename), source);
     }
   };

I run the following command: docker run --rm -it --cap-add SYS_ADMIN --volume wecDir:/output wec https://www.edps.europa.eu/ --output 55 --overwrite true

I am not sure, if this is a appropriate way to share the changes with you, as I am quite new to git. If you need it in another way, please let me know.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant