mirror of
https://github.com/webrecorder/browsertrix-crawler.git
synced 2025-10-19 14:33:17 +00:00
logging and beheaviors improvements (#389)
- run behaviors: check if behaviors object exists before trying to run behaviors to avoid failure message - skip behaviors if frame no longer attached / has empty URL
This commit is contained in:
parent
c6cbbc1a17
commit
165a9787af
2 changed files with 16 additions and 4 deletions
12
crawler.js
12
crawler.js
|
@ -589,7 +589,13 @@ self.__bx_behaviors.selectMainBehavior();
|
|||
logger.info("Running behaviors", {frames: frames.length, frameUrls: frames.map(frame => frame.url()), ...logDetails}, "behavior");
|
||||
|
||||
const results = await Promise.allSettled(
|
||||
frames.map(frame => this.browser.evaluateWithCLI(page, frame, cdp, "self.__bx_behaviors.run();", logDetails, "behavior"))
|
||||
frames.map(frame => this.browser.evaluateWithCLI(page, frame, cdp, `
|
||||
if (!self.__bx_behaviors) {
|
||||
console.error("__bx_behaviors missing, can't run behaviors");
|
||||
} else {
|
||||
self.__bx_behaviors.run();
|
||||
}`
|
||||
, logDetails, "behavior"))
|
||||
);
|
||||
|
||||
for (const {status, reason} in results) {
|
||||
|
@ -1177,8 +1183,8 @@ self.__bx_behaviors.selectMainBehavior();
|
|||
frames = await Promise.allSettled(frames.map((frame) => this.shouldIncludeFrame(frame, logDetails)));
|
||||
|
||||
data.filteredFrames = frames.filter((x) => {
|
||||
if (x.status === "fulfilled" && x.value) {
|
||||
return true;
|
||||
if (x.status === "fulfilled") {
|
||||
return !!x.value;
|
||||
}
|
||||
logger.warn("Error in iframe check", {reason: x.reason, ...logDetails});
|
||||
return false;
|
||||
|
|
|
@ -163,7 +163,13 @@ export class BaseBrowser
|
|||
}
|
||||
|
||||
async evaluateWithCLI_(cdp, frame, cdpContextId, funcString, logData, contextName) {
|
||||
let details = {frameUrl: frame.url(), ...logData};
|
||||
const frameUrl = frame.url();
|
||||
let details = {frameUrl, ...logData};
|
||||
|
||||
if (!frameUrl || frame.isDetached()) {
|
||||
logger.info("Run Script Skipped, frame no longer attached or has no URL", details, contextName);
|
||||
return false;
|
||||
}
|
||||
|
||||
logger.info("Run Script Started", details, contextName);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue