mirror of
https://github.com/webrecorder/browsertrix-crawler.git
synced 2025-10-19 14:33:17 +00:00
Autoclick Support (#729)
Adds support for autoclick behavior: - Adds new `autoclick` behavior option to `--behaviors`, but not enabling by default - Adds support for new exposed function `__bx_addSet` which allows autoclick behavior to persist state about links that have already been clicked to avoid duplicates, only used if link has an href - Adds a new pageFinished flag on the worker state. - Adds a on('dialog') handler to reject onbeforeunload page navigations, when in behavior (page not finished), but accept when page is finished - to allow navigation away only when behaviors are done - Update to browsertrix-behaviors 0.7.0, which supports autoclick - Add --clickSelector option to customize elements that will be clicked, defaulting to `a`. - Add --linkSelector as alias for --selectLinks for consistency - Unknown options for --behaviors printed as warnings, instead of hard exit, for forward compatibility for new behavior types in the future Fixes #728, also #216, #665, #31
This commit is contained in:
parent
871490758a
commit
b7150f1343
14 changed files with 259 additions and 108 deletions
|
@ -17,6 +17,7 @@ import { CDPSession, Page, PuppeteerLifeCycleEvent } from "puppeteer-core";
|
|||
import { getInfoString } from "./util/file_reader.js";
|
||||
import { DISPLAY } from "./util/constants.js";
|
||||
import { initProxy } from "./util/proxy.js";
|
||||
//import { sleep } from "./util/timing.js";
|
||||
|
||||
const profileHTML = fs.readFileSync(
|
||||
new URL("../html/createProfile.html", import.meta.url),
|
||||
|
@ -437,6 +438,27 @@ class InteractiveBrowser {
|
|||
|
||||
// attempt to keep everything to initial tab if headless
|
||||
if (this.params.headless) {
|
||||
void cdp.send("Target.setDiscoverTargets", { discover: true });
|
||||
|
||||
cdp.on("Target.targetCreated", async (params) => {
|
||||
const { targetInfo } = params;
|
||||
const { type, openerFrameId } = targetInfo;
|
||||
|
||||
if (type === "page" && openerFrameId) {
|
||||
await cdp.send("Target.closeTarget", {
|
||||
targetId: params.targetInfo.targetId,
|
||||
});
|
||||
}
|
||||
|
||||
await cdp.send("Runtime.runIfWaitingForDebugger");
|
||||
});
|
||||
|
||||
void cdp.send("Target.setAutoAttach", {
|
||||
autoAttach: true,
|
||||
waitForDebuggerOnStart: true,
|
||||
flatten: false,
|
||||
});
|
||||
|
||||
cdp.send("Page.enable").catch((e) => logger.warn("Page.enable error", e));
|
||||
|
||||
cdp.on("Page.windowOpen", async (resp) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue