Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addLink: support dynamic links added from behaviors #69

Merged
merged 2 commits into from Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 43 additions & 1 deletion dist/behaviors.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "browsertrix-behaviors",
"version": "0.5.2",
"version": "0.5.3",
"main": "index.js",
"author": "Webrecorder Software",
"license": "AGPL-3.0-or-later",
Expand Down
2 changes: 1 addition & 1 deletion src/autoplay.ts
Expand Up @@ -41,7 +41,7 @@ export class Autoplay extends BackgroundBehavior {
const run = true;

if (this.polling) {
return
return;
}

this.polling = true;
Expand Down
13 changes: 12 additions & 1 deletion src/autoscroll.ts
@@ -1,5 +1,5 @@
import { Behavior } from "./lib/behavior";
import { sleep, waitUnit, xpathNode, isInViewport, waitUntil } from "./lib/utils";
import { sleep, waitUnit, xpathNode, isInViewport, waitUntil, behaviorLog, addLink } from "./lib/utils";
import { type AutoFetcher } from "./autofetcher";


Expand All @@ -11,6 +11,8 @@ export class AutoScroll extends Behavior {
lastScrollPos: number;
samePosCount: number;

origPath: string;

constructor(autofetcher: AutoFetcher) {
super();

Expand All @@ -24,6 +26,8 @@ export class AutoScroll extends Behavior {

this.lastScrollPos = -1;
this.samePosCount = 0;

this.origPath = document.location.pathname;
}

static id = "Autoscroll";
Expand Down Expand Up @@ -113,6 +117,13 @@ export class AutoScroll extends Behavior {
let lastScrollHeight = self.document.scrollingElement.scrollHeight;

while (this.canScrollMore()) {
if (document.location.pathname !== this.origPath) {
behaviorLog("Location Changed, stopping scroll: " +
`${document.location.pathname} != ${this.origPath}`, "info");
addLink(document.location.href);
ikreymer marked this conversation as resolved.
Show resolved Hide resolved
return;
}

const scrollHeight = self.document.scrollingElement.scrollHeight;

if (scrollHeight > lastScrollHeight) {
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Expand Up @@ -89,7 +89,7 @@ export class BehaviorManager {
this.behaviors.push(new Autoplay(this.autofetch, opts.startEarly));
}

if (self.window.top !== self.window) {
if (self.window.top !== self.window && window["__WB_replay_top"] !== self.window) {
return;
}

Expand Down Expand Up @@ -136,9 +136,9 @@ export class BehaviorManager {
if (this.mainBehavior) {
this.behaviors.push(this.mainBehavior);

if (this.mainBehavior instanceof Behavior) {
// if (this.mainBehavior instanceof Behavior) {

}
// }
ikreymer marked this conversation as resolved.
Show resolved Hide resolved
if (this.mainBehavior instanceof BehaviorRunner) {
return this.mainBehavior.behaviorProps.id;
}
Expand All @@ -154,7 +154,7 @@ export class BehaviorManager {
}

if (typeof(behaviorClass.id) !== "string") {
behaviorLog(`Behavior class must have a string string "id" property`, "error");
behaviorLog("Behavior class must have a string string \"id\" property", "error");
return;
}

Expand Down
6 changes: 6 additions & 0 deletions src/lib/utils.ts
Expand Up @@ -59,6 +59,12 @@ export function behaviorLog(data, type = "debug") {
}
}

export function addLink(url) {
if (self["__bx_addLink"]) {
self["__bx_addLink"](url);
}
}

export async function openWindow(url) {
if (self["__bx_open"]) {
const p = new Promise((resolve) => self["__bx_openResolve"] = resolve);
Expand Down