Skip to content

Commit 4d7c728

Browse files
tw4likreymer
andauthored
Log behavior name and siteSpecific: true for site-specific behaviors (#92)
* Ensure all built-in behaviors have a static id * Log behavior id and siteSpecific bool when behaviors log on step * Log built-in behavior logs at debug logLevel * add error() for behavior logging exceptions from run() * Update autoscroll test * bump to 0.8.2 --------- Co-authored-by: Ilya Kreymer <[email protected]>
1 parent 8db2d42 commit 4d7c728

File tree

6 files changed

+25
-15
lines changed

6 files changed

+25
-15
lines changed

.github/workflows/autoscroll.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ jobs:
3535
run: docker pull $BROWSERTRIX_IMAGE
3636

3737
- name: run crawl
38-
run: docker run -v $PWD/dist/behaviors.js:/app/node_modules/browsertrix-behaviors/dist/behaviors.js $BROWSERTRIX_IMAGE crawl --url https://www.iana.org/numbers --limit 1 --logging behaviors --behaviors autoplay,autofetch,autoscroll > ./log
38+
run: docker run -v $PWD/dist/behaviors.js:/app/node_modules/browsertrix-behaviors/dist/behaviors.js $BROWSERTRIX_IMAGE crawl --url https://www.iana.org/numbers --limit 1 --logging debug --context behaviorScript --behaviors autoscroll > ./log
3939

40-
- name: cat log
41-
run: cat ./log
40+
- name: check for autoscroll debug log line
41+
run: grep 'Skipping autoscroll, page seems to not be responsive to scrolling events' ./log
4242

43-
- name: compare crawl log to expected
44-
run: cat ./log | jq -c 'select(.context == "behaviorScript") | .details' | diff - ./test/expected-autoscroll.log
43+
- name: check that state is logged as well
44+
run: grep '{"state":{"segments":1}' ./log
4545

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "browsertrix-behaviors",
3-
"version": "0.8.1",
3+
"version": "0.8.2",
44
"main": "index.js",
55
"author": "Webrecorder Software",
66
"license": "AGPL-3.0-or-later",

src/autoclick.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export class AutoClick extends BackgroundBehavior
1010
selector: string;
1111
seenElem = new WeakSet<HTMLElement>();
1212

13+
static id = "Autoclick";
14+
1315
constructor(selector = "a") {
1416
super();
1517
this.selector = selector;

src/autofetcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class AutoFetcher extends BackgroundBehavior {
3737
active: boolean;
3838
running = false;
3939

40-
static id = "AutoFetcher";
40+
static id = "Autofetcher";
4141

4242
constructor(active = false, headers = null, startEarly = false) {
4343
super();

src/lib/behavior.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ export class BackgroundBehavior {
77
behaviorLog(msg, "debug");
88
}
99

10+
error(msg) {
11+
behaviorLog(msg, "error");
12+
}
13+
1014
log(msg) {
1115
behaviorLog(msg, "info");
1216
}
@@ -43,14 +47,14 @@ export class Behavior extends BackgroundBehavior {
4347
async run() {
4448
try {
4549
for await (const step of this) {
46-
this.log(step);
50+
this.debug(step);
4751
if (this.paused) {
4852
await this.paused;
4953
}
5054
}
51-
this.log(this.getState("done!"));
55+
this.debug(this.getState("done!"));
5256
} catch (e) {
53-
this.log(this.getState(e));
57+
this.error(e.toString());
5458
}
5559
}
5660

@@ -167,14 +171,20 @@ export class BehaviorRunner extends BackgroundBehavior {
167171
async run() {
168172
try {
169173
for await (const step of this.inst.run(this.ctx)) {
170-
this.log(step);
174+
let logStep;
175+
if (typeof step === "string" || step instanceof String) {
176+
logStep = {msg: step}
177+
} else {
178+
logStep = step;
179+
}
180+
this.log({...logStep, behavior: this.behaviorProps.id, siteSpecific: true});
171181
if (this.paused) {
172182
await this.paused;
173183
}
174184
}
175-
this.log("done!");
185+
this.log({msg: "done!", behavior: this.behaviorProps.id, siteSpecific: true});
176186
} catch (e) {
177-
this.log(e.toString());
187+
this.error({msg: e.toString(), behavior: this.behaviorProps.id, siteSpecific: true});
178188
}
179189
}
180190

test/expected-autoscroll.log

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)