0.4.1 Release! (#70)
* optimization: don't intercept requests if no blockRules set
* page load: set waitUntil to use networkidle2 instead of networkidle0 as reasonable default for most pages
* add --behaviorTimeout to set max running time for behaviors (defaults to 90 seconds)
* refactor profile loadProfile/saveProfile to util/browser.js
- support augmenting existing profile when creating a new profile
* screencasting: convert newContext to window instead of page by default, instead of just warning about it
* shared multiplatform image support:
- determine browser exe from list of options, getBrowserExe() returns current exe
- supports running with 'google-chrome' under amd64, and 'chromium-browser' under arm64
- update to multiplatform oldwebtoday/chrome:91 as browser image
- enable multiplatform build with latest build-push-action@v2
* seeds: add trim() to seed URLs
* logging: reduce initial debug logging, enable only if '--logging debug' is set. log if profile, text-extraction enabled, and post-processing stages automatically
* profile creation: add --windowSize flag, set default to 1600x900, default to loading Application tab, tweak UI styles
* extractLinks: support passing in custom property to get link, and also loading as an attribute via getAttribute. Fixes #25
* update CHANGES and README with new features
* bump version to 0.4.1
2021-07-22 14:24:51 -07:00
|
|
|
const child_process = require("child_process");
|
|
|
|
const fs = require("fs");
|
|
|
|
const path = require("path");
|
|
|
|
const os = require("os");
|
2022-03-14 14:44:24 -07:00
|
|
|
const request = require("request");
|
0.4.1 Release! (#70)
* optimization: don't intercept requests if no blockRules set
* page load: set waitUntil to use networkidle2 instead of networkidle0 as reasonable default for most pages
* add --behaviorTimeout to set max running time for behaviors (defaults to 90 seconds)
* refactor profile loadProfile/saveProfile to util/browser.js
- support augmenting existing profile when creating a new profile
* screencasting: convert newContext to window instead of page by default, instead of just warning about it
* shared multiplatform image support:
- determine browser exe from list of options, getBrowserExe() returns current exe
- supports running with 'google-chrome' under amd64, and 'chromium-browser' under arm64
- update to multiplatform oldwebtoday/chrome:91 as browser image
- enable multiplatform build with latest build-push-action@v2
* seeds: add trim() to seed URLs
* logging: reduce initial debug logging, enable only if '--logging debug' is set. log if profile, text-extraction enabled, and post-processing stages automatically
* profile creation: add --windowSize flag, set default to 1600x900, default to loading Application tab, tweak UI styles
* extractLinks: support passing in custom property to get link, and also loading as an attribute via getAttribute. Fixes #25
* update CHANGES and README with new features
* bump version to 0.4.1
2021-07-22 14:24:51 -07:00
|
|
|
|
|
|
|
const profileDir = fs.mkdtempSync(path.join(os.tmpdir(), "profile-"));
|
|
|
|
|
2022-03-14 14:44:24 -07:00
|
|
|
module.exports.loadProfile = async function(profileFilename) {
|
|
|
|
if (profileFilename &&
|
|
|
|
(profileFilename.startsWith("http:") || profileFilename.startsWith("https:"))) {
|
|
|
|
|
|
|
|
const targetFilename = "/tmp/profile.tar.gz";
|
|
|
|
|
|
|
|
console.log(`Downloading ${profileFilename} to ${targetFilename}`);
|
|
|
|
|
|
|
|
const p = new Promise((resolve, reject) => {
|
|
|
|
request.get(profileFilename).
|
|
|
|
on("error", (err) => reject(err)).
|
|
|
|
pipe(fs.createWriteStream(targetFilename)).
|
|
|
|
on("finish", () => resolve());
|
|
|
|
});
|
|
|
|
|
|
|
|
await p;
|
|
|
|
|
|
|
|
profileFilename = targetFilename;
|
|
|
|
}
|
|
|
|
|
0.4.1 Release! (#70)
* optimization: don't intercept requests if no blockRules set
* page load: set waitUntil to use networkidle2 instead of networkidle0 as reasonable default for most pages
* add --behaviorTimeout to set max running time for behaviors (defaults to 90 seconds)
* refactor profile loadProfile/saveProfile to util/browser.js
- support augmenting existing profile when creating a new profile
* screencasting: convert newContext to window instead of page by default, instead of just warning about it
* shared multiplatform image support:
- determine browser exe from list of options, getBrowserExe() returns current exe
- supports running with 'google-chrome' under amd64, and 'chromium-browser' under arm64
- update to multiplatform oldwebtoday/chrome:91 as browser image
- enable multiplatform build with latest build-push-action@v2
* seeds: add trim() to seed URLs
* logging: reduce initial debug logging, enable only if '--logging debug' is set. log if profile, text-extraction enabled, and post-processing stages automatically
* profile creation: add --windowSize flag, set default to 1600x900, default to loading Application tab, tweak UI styles
* extractLinks: support passing in custom property to get link, and also loading as an attribute via getAttribute. Fixes #25
* update CHANGES and README with new features
* bump version to 0.4.1
2021-07-22 14:24:51 -07:00
|
|
|
if (profileFilename) {
|
2022-03-14 14:44:24 -07:00
|
|
|
try {
|
|
|
|
child_process.execSync("tar xvfz " + profileFilename, {cwd: profileDir});
|
|
|
|
} catch (e) {
|
|
|
|
console.error(`Profile filename ${profileFilename} not a valid tar.gz`);
|
|
|
|
}
|
0.4.1 Release! (#70)
* optimization: don't intercept requests if no blockRules set
* page load: set waitUntil to use networkidle2 instead of networkidle0 as reasonable default for most pages
* add --behaviorTimeout to set max running time for behaviors (defaults to 90 seconds)
* refactor profile loadProfile/saveProfile to util/browser.js
- support augmenting existing profile when creating a new profile
* screencasting: convert newContext to window instead of page by default, instead of just warning about it
* shared multiplatform image support:
- determine browser exe from list of options, getBrowserExe() returns current exe
- supports running with 'google-chrome' under amd64, and 'chromium-browser' under arm64
- update to multiplatform oldwebtoday/chrome:91 as browser image
- enable multiplatform build with latest build-push-action@v2
* seeds: add trim() to seed URLs
* logging: reduce initial debug logging, enable only if '--logging debug' is set. log if profile, text-extraction enabled, and post-processing stages automatically
* profile creation: add --windowSize flag, set default to 1600x900, default to loading Application tab, tweak UI styles
* extractLinks: support passing in custom property to get link, and also loading as an attribute via getAttribute. Fixes #25
* update CHANGES and README with new features
* bump version to 0.4.1
2021-07-22 14:24:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return profileDir;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.saveProfile = function(profileFilename) {
|
|
|
|
child_process.execFileSync("tar", ["cvfz", profileFilename, "./"], {cwd: profileDir});
|
|
|
|
};
|
|
|
|
|
2022-03-18 10:32:59 -07:00
|
|
|
function getBrowserExe() {
|
0.4.1 Release! (#70)
* optimization: don't intercept requests if no blockRules set
* page load: set waitUntil to use networkidle2 instead of networkidle0 as reasonable default for most pages
* add --behaviorTimeout to set max running time for behaviors (defaults to 90 seconds)
* refactor profile loadProfile/saveProfile to util/browser.js
- support augmenting existing profile when creating a new profile
* screencasting: convert newContext to window instead of page by default, instead of just warning about it
* shared multiplatform image support:
- determine browser exe from list of options, getBrowserExe() returns current exe
- supports running with 'google-chrome' under amd64, and 'chromium-browser' under arm64
- update to multiplatform oldwebtoday/chrome:91 as browser image
- enable multiplatform build with latest build-push-action@v2
* seeds: add trim() to seed URLs
* logging: reduce initial debug logging, enable only if '--logging debug' is set. log if profile, text-extraction enabled, and post-processing stages automatically
* profile creation: add --windowSize flag, set default to 1600x900, default to loading Application tab, tweak UI styles
* extractLinks: support passing in custom property to get link, and also loading as an attribute via getAttribute. Fixes #25
* update CHANGES and README with new features
* bump version to 0.4.1
2021-07-22 14:24:51 -07:00
|
|
|
const files = [process.env.BROWSER_BIN, "/usr/bin/google-chrome", "/usr/bin/chromium-browser"];
|
|
|
|
for (const file of files) {
|
|
|
|
if (file && fs.existsSync(file)) {
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2022-03-18 10:32:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports.getBrowserExe = getBrowserExe;
|
|
|
|
|
|
|
|
|
|
|
|
function getDefaultUA() {
|
|
|
|
let version = process.env.BROWSER_VERSION;
|
|
|
|
|
|
|
|
try {
|
|
|
|
version = child_process.execFileSync(getBrowserExe(), ["--version"], {encoding: "utf8"});
|
|
|
|
version = version.match(/[\d.]+/)[0];
|
|
|
|
} catch(e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return `Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${version} Safari/537.36`;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports.getDefaultUA = getDefaultUA;
|
|
|
|
|
|
|
|
|
|
|
|
module.exports.chromeArgs = (proxy, userAgent=null, extraArgs=[]) => {
|
|
|
|
// Chrome Flags, including proxy server
|
|
|
|
const args = [
|
|
|
|
...(process.env.CHROME_FLAGS ?? "").split(" ").filter(Boolean),
|
|
|
|
"--no-xshm", // needed for Chrome >80 (check if puppeteer adds automatically)
|
|
|
|
"--no-sandbox",
|
|
|
|
"--disable-background-media-suspend",
|
|
|
|
"--autoplay-policy=no-user-gesture-required",
|
|
|
|
"--disable-features=Translate,LazyFrameLoading,IsolateOrigins,site-per-process",
|
|
|
|
"--disable-popup-blocking",
|
|
|
|
"--disable-backgrounding-occluded-windows",
|
|
|
|
`--user-agent=${userAgent || getDefaultUA()}`,
|
|
|
|
...extraArgs,
|
|
|
|
];
|
|
|
|
|
|
|
|
if (proxy) {
|
|
|
|
args.push(`--proxy-server=http://${process.env.PROXY_HOST}:${process.env.PROXY_PORT}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
return args;
|
0.4.1 Release! (#70)
* optimization: don't intercept requests if no blockRules set
* page load: set waitUntil to use networkidle2 instead of networkidle0 as reasonable default for most pages
* add --behaviorTimeout to set max running time for behaviors (defaults to 90 seconds)
* refactor profile loadProfile/saveProfile to util/browser.js
- support augmenting existing profile when creating a new profile
* screencasting: convert newContext to window instead of page by default, instead of just warning about it
* shared multiplatform image support:
- determine browser exe from list of options, getBrowserExe() returns current exe
- supports running with 'google-chrome' under amd64, and 'chromium-browser' under arm64
- update to multiplatform oldwebtoday/chrome:91 as browser image
- enable multiplatform build with latest build-push-action@v2
* seeds: add trim() to seed URLs
* logging: reduce initial debug logging, enable only if '--logging debug' is set. log if profile, text-extraction enabled, and post-processing stages automatically
* profile creation: add --windowSize flag, set default to 1600x900, default to loading Application tab, tweak UI styles
* extractLinks: support passing in custom property to get link, and also loading as an attribute via getAttribute. Fixes #25
* update CHANGES and README with new features
* bump version to 0.4.1
2021-07-22 14:24:51 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-02-20 22:22:19 -08:00
|
|
|
module.exports.evaluateWithCLI = async (frame, funcString) => {
|
|
|
|
const context = await frame.executionContext();
|
|
|
|
|
|
|
|
// from puppeteer _evaluateInternal() but with includeCommandLineAPI: true
|
|
|
|
const contextId = context._contextId;
|
|
|
|
const expression = funcString + "\n//# sourceURL=__puppeteer_evaluation_script__";
|
|
|
|
|
|
|
|
const { exceptionDetails, result: remoteObject } = await context._client
|
|
|
|
.send("Runtime.evaluate", {
|
|
|
|
expression,
|
|
|
|
contextId,
|
|
|
|
returnByValue: true,
|
|
|
|
awaitPromise: true,
|
|
|
|
userGesture: true,
|
|
|
|
includeCommandLineAPI: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (exceptionDetails) {
|
|
|
|
throw new Error(
|
|
|
|
"Behavior Evaluation Failed" + exceptionDetails.text
|
|
|
|
);
|
|
|
|
}
|
0.4.1 Release! (#70)
* optimization: don't intercept requests if no blockRules set
* page load: set waitUntil to use networkidle2 instead of networkidle0 as reasonable default for most pages
* add --behaviorTimeout to set max running time for behaviors (defaults to 90 seconds)
* refactor profile loadProfile/saveProfile to util/browser.js
- support augmenting existing profile when creating a new profile
* screencasting: convert newContext to window instead of page by default, instead of just warning about it
* shared multiplatform image support:
- determine browser exe from list of options, getBrowserExe() returns current exe
- supports running with 'google-chrome' under amd64, and 'chromium-browser' under arm64
- update to multiplatform oldwebtoday/chrome:91 as browser image
- enable multiplatform build with latest build-push-action@v2
* seeds: add trim() to seed URLs
* logging: reduce initial debug logging, enable only if '--logging debug' is set. log if profile, text-extraction enabled, and post-processing stages automatically
* profile creation: add --windowSize flag, set default to 1600x900, default to loading Application tab, tweak UI styles
* extractLinks: support passing in custom property to get link, and also loading as an attribute via getAttribute. Fixes #25
* update CHANGES and README with new features
* bump version to 0.4.1
2021-07-22 14:24:51 -07:00
|
|
|
|
2022-02-20 22:22:19 -08:00
|
|
|
return remoteObject.value;
|
|
|
|
};
|
0.4.1 Release! (#70)
* optimization: don't intercept requests if no blockRules set
* page load: set waitUntil to use networkidle2 instead of networkidle0 as reasonable default for most pages
* add --behaviorTimeout to set max running time for behaviors (defaults to 90 seconds)
* refactor profile loadProfile/saveProfile to util/browser.js
- support augmenting existing profile when creating a new profile
* screencasting: convert newContext to window instead of page by default, instead of just warning about it
* shared multiplatform image support:
- determine browser exe from list of options, getBrowserExe() returns current exe
- supports running with 'google-chrome' under amd64, and 'chromium-browser' under arm64
- update to multiplatform oldwebtoday/chrome:91 as browser image
- enable multiplatform build with latest build-push-action@v2
* seeds: add trim() to seed URLs
* logging: reduce initial debug logging, enable only if '--logging debug' is set. log if profile, text-extraction enabled, and post-processing stages automatically
* profile creation: add --windowSize flag, set default to 1600x900, default to loading Application tab, tweak UI styles
* extractLinks: support passing in custom property to get link, and also loading as an attribute via getAttribute. Fixes #25
* update CHANGES and README with new features
* bump version to 0.4.1
2021-07-22 14:24:51 -07:00
|
|
|
|
2022-03-18 10:32:59 -07:00
|
|
|
|
|
|
|
module.exports.sleep = async (time) => {
|
|
|
|
return new Promise(resolve => setTimeout(resolve, time));
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|