GithubHelp home page GithubHelp logo

Comments (4)

sdht0 avatar sdht0 commented on May 31, 2024

I managed to get this working with the following diff for my use case. Feel free to pick this up and get it commit ready.

diff --git a/back-ends/puppeteer.js b/back-ends/puppeteer.js
index 4999b3d..4b25b90 100644
--- a/back-ends/puppeteer.js
+++ b/back-ends/puppeteer.js
@@ -187,10 +187,15 @@ async function pageGoto(page, options) {
 		timeout: options.browserLoadMaxTime || 0,
 		waitUntil: options.browserWaitUntil || NETWORK_IDLE_STATE
 	};
+	var response;
 	if (options.content) {
-		await page.goto(options.url, { waitUntil: "domcontentloaded" });
+		response = await page.goto(options.url, { waitUntil: "domcontentloaded" });
 		await page.setContent(options.content, loadOptions);
 	} else {
-		await page.goto(options.url, loadOptions);
+		response = await page.goto(options.url, loadOptions);
+	}
+	if (response.status() !== 200 ) {
+		process.exitCode = 2;
+		throw new Error(`Got response '${response.status()}'`);
 	}
 }
diff --git a/single-file-cli-api.js b/single-file-cli-api.js
index d7c455c..77d8790 100644
--- a/single-file-cli-api.js
+++ b/single-file-cli-api.js
@@ -277,6 +277,9 @@ async function capturePage(options) {
 		} else {
 			console.error(error.message || error, message); // eslint-disable-line no-console
 		}
+		if (!process.exitCode || process.exitCode === 0) {
+			process.exitCode = 1;
+		}
 	}
 }

from single-file-cli.

gildas-lormeau avatar gildas-lormeau commented on May 31, 2024

Thank you, I think I will integrate your changes but behind a flag. Considering a 404 as an error can be controversial.

from single-file-cli.

Yakabuff avatar Yakabuff commented on May 31, 2024

@gildas-lormeau
Instead of throwing an error and exiting out, could we just implement a flag --output-result that outputs http response code, url, http headers in stdout for users to parse?

from single-file-cli.

Yakabuff avatar Yakabuff commented on May 31, 2024

@gildas-lormeau I made a PR to address this: #31

from single-file-cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.