Comments (4)
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.
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.
@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.
@gildas-lormeau I made a PR to address this: #31
from single-file-cli.
Related Issues (20)
- Error: command not found, after `npm install -g "gildas-lormeau/single-file-cli"` HOT 5
- `Cannot read properties of undefined` when following the docker example HOT 2
- Stacktrace when running SingleFile CLI for a particular website HOT 1
- Skips First URL in the list of URLs HOT 3
- --save-original-urls does not work on cli HOT 2
- Running singlefile-cli with a chrome extension HOT 1
- Unable to download a particular website using cli HOT 9
- where to set ignoreHTTPSErrors config HOT 3
- working with a given url seems to dump code into the terminal
- feature suggestion: convert IFRAMEs into embedded content
- feature suggestion: verbose mode (hangs on URL)
- Page download failing for Youtube when using browser cookie HOT 2
- How can I use docker cli instead of curl with cookie.json? HOT 5
- When spawning singlefile from within a docker container, it will leave defunct chrome processes behind.
- No option to disable saved date header HOT 2
- Feature request: Add support for configuration files and add an argument to read the file from a path.
- --browser-script after --browser-executable-path results in silent failure HOT 2
- Recent tagged Docker image? HOT 1
- Failed to launch the browser process! (Apple Silicon) HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from single-file-cli.