Skip to content

Commit 7c0c451

Browse files
committed
fix(core): isVisible fix, scroll below 0 fix
fix(core): nested commands causing infinite loop with long command stack
1 parent aa5227a commit 7c0c451

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

core/lib/Tab.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export default class Tab extends TypedEventEmitter<ITabEventParams> {
141141
this.waitForLocation,
142142
this.waitForNewTab,
143143
this.waitForResource,
144+
// DO NOT ADD waitForReady
144145
]);
145146
}
146147

@@ -226,7 +227,7 @@ export default class Tab extends TypedEventEmitter<ITabEventParams> {
226227
let finalResourceId = resourceid;
227228
// if no resource id, this is a request for the default resource (page)
228229
if (!resourceid) {
229-
await this.waitForLoad('READY');
230+
await this.locationTracker.waitFor('READY');
230231
finalResourceId = await this.locationTracker.waitForLocationResourceId();
231232
}
232233

@@ -294,7 +295,7 @@ export default class Tab extends TypedEventEmitter<ITabEventParams> {
294295
): Promise<IExecJsPathResult<T>> {
295296
// if nothing loaded yet, return immediately
296297
if (!this.navigationTracker.top) return null;
297-
await this.waitForLoad('READY');
298+
await this.locationTracker.waitFor('READY');
298299
return this.domEnv.execJsPath<T>(jsPath, propertiesToExtract);
299300
}
300301

@@ -307,12 +308,12 @@ export default class Tab extends TypedEventEmitter<ITabEventParams> {
307308
}
308309

309310
public async getLocationHref(): Promise<string> {
310-
await this.waitForLoad('READY');
311+
await this.locationTracker.waitFor('READY');
311312
return this.domEnv.locationHref();
312313
}
313314

314315
public async getCookies(): Promise<ICookie[]> {
315-
await this.waitForLoad('READY');
316+
await this.locationTracker.waitFor('READY');
316317
return await this.session.browserContext.getCookies(
317318
new URL(this.puppetPage.mainFrame.securityOrigin ?? this.puppetPage.mainFrame.url),
318319
);
@@ -323,7 +324,7 @@ export default class Tab extends TypedEventEmitter<ITabEventParams> {
323324
value: string,
324325
options?: ISetCookieOptions,
325326
): Promise<boolean> {
326-
await this.waitForLoad('READY');
327+
await this.locationTracker.waitFor('READY');
327328
await this.session.browserContext.addCookies([
328329
{
329330
name,
@@ -431,7 +432,7 @@ export default class Tab extends TypedEventEmitter<ITabEventParams> {
431432
return this.waitForDom(jsPath, options);
432433
}
433434

434-
public waitForLoad(status: ILocationStatus | 'READY', options?: IWaitForOptions): Promise<void> {
435+
public waitForLoad(status: ILocationStatus, options?: IWaitForOptions): Promise<void> {
435436
return this.locationTracker.waitFor(status, options);
436437
}
437438

emulate-humans/ghost/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ export default class HumanEmulatorGhost {
252252
const scrollX = shouldScrollX ? Math.round(point.x) : startScrollOffset.x;
253253
const scrollY = shouldScrollY ? Math.round(point.y) : startScrollOffset.y;
254254
if (scrollY === lastPoint.y && scrollX === lastPoint.x) continue;
255+
if (scrollY < 0 || scrollX < 0) continue;
255256

256257
point = {
257258
x: scrollX,

injected-scripts/scripts/jsPath.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,12 @@ class ObjectAtPath {
307307
const rect = this.boundingClientRect;
308308
const hasDimensions = rect.width && rect.height;
309309
if (!hasDimensions) return false;
310-
return rect.bottom < window.innerHeight && rect.right < window.innerWidth;
310+
return (
311+
rect.top > 0 &&
312+
rect.bottom < window.innerHeight &&
313+
rect.left > 0 &&
314+
rect.right < window.innerWidth
315+
);
311316
}
312317
return false;
313318
}

0 commit comments

Comments
 (0)