Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions browser_patches/firefox/juggler/content/Runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ const disallowedMessageCategories = new Set([
class Runtime {
constructor(isWorker = false) {
this._debugger = new Debugger();
// A debuggee global with these flags unset is pinned to the debuggable wasm/asm.js
// baseline tier, with the optimizing compiler disabled entirely.
this._debugger.allowUnobservedWasm = true;
this._debugger.allowUnobservedAsmJS = true;
this._pendingPromises = new Map();
this._executionContexts = new Map();
this._windowToExecutionContext = new Map();
Expand Down
4 changes: 4 additions & 0 deletions browser_patches/firefox/juggler/content/WorkerMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const runtime = new Runtime(true /* isWorker */);
// Create execution context in the runtime only when the script
// source was actually evaluated in it.
const dbg = new Debugger(global);
// A debuggee global with these flags unset is pinned to the debuggable wasm/asm.js
// baseline tier, with the optimizing compiler disabled entirely.
dbg.allowUnobservedWasm = true;
dbg.allowUnobservedAsmJS = true;
if (dbg.findScripts({global}).length) {
runtime.createExecutionContext(null /* domWindow */, global, {});
} else {
Expand Down
113 changes: 63 additions & 50 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"@vitejs/plugin-basic-ssl": "2.3.0",
"@vitejs/plugin-react": "6.0.3",
"@zip.js/zip.js": "2.7.73",
"chokidar": "3.6.0",
"chokidar": "4.0.3",
"chromium-bidi": "12.1.0",
"colors": "1.4.0",
"commander": "15.0.0",
Expand Down
59 changes: 58 additions & 1 deletion packages/extension/src/relayConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ const CHROME_EVENT_METHODS = [
'chrome.tabs.onRemoved',
];

const REATTACH_DELAY_MS = 150;
const REATTACH_VERIFY_MS = 2500;
const REATTACH_COOLDOWN_MS = 3000;

export class RelayConnection {
private _ws: WebSocket;
// Tabs whose debugger we have explicitly attached for this connection.
Expand All @@ -62,6 +66,8 @@ export class RelayConnection {
private _hasEverAttached = false;
private _eventListeners: Array<{ remove: () => void }> = [];
private _closed = false;
private _pendingReattach = new Set<number>();
private _recentReattach = new Set<number>();

onclose?: () => void;
ontabattached?: (tabId: number) => void;
Expand Down Expand Up @@ -125,6 +131,7 @@ export class RelayConnection {
private _notifyTabAttached(tabId: number): void {
this._attachedTabs.add(tabId);
this._hasEverAttached = true;
this._pendingReattach.delete(tabId);
this.ontabattached?.(tabId);
}

Expand All @@ -148,6 +155,8 @@ export class RelayConnection {
if (this._closed)
return;
this._closed = true;
this._pendingReattach.clear();
this._recentReattach.clear();
for (const l of this._eventListeners)
l.remove();
this._eventListeners = [];
Expand All @@ -159,7 +168,7 @@ export class RelayConnection {
}

private _checkLastTabDetached(): void {
if (this._hasEverAttached && this._attachedTabs.size === 0)
if (this._hasEverAttached && this._attachedTabs.size === 0 && this._pendingReattach.size === 0)
this.close('All controlled tabs detached');
}

Expand All @@ -172,11 +181,59 @@ export class RelayConnection {
this._sendMessage({ method: fullMethod, params: args });
// chrome.debugger.onDetach is the single source of truth for detach bookkeeping.
if (fullMethod === 'chrome.debugger.onDetach') {
const reason = args[1] as string | undefined;
this._notifyTabDetached(tabId);
if (reason === 'target_closed' && this._maybeScheduleReattach(tabId))
return;
this._checkLastTabDetached();
}
}

private _maybeScheduleReattach(tabId: number): boolean {
if (this._closed)
return false;
if (this._recentReattach.has(tabId)) {
debugLog(`Not re-attaching tab ${tabId}: re-detached within ${REATTACH_COOLDOWN_MS}ms`);
return false;
}
this._recentReattach.add(tabId);
setTimeout(() => this._recentReattach.delete(tabId), REATTACH_COOLDOWN_MS);
this._pendingReattach.add(tabId);
setTimeout(() => void this._tryReattach(tabId), REATTACH_DELAY_MS);
return true;
}

private _reattachAborted(tabId: number): boolean {
return this._closed || !this._pendingReattach.has(tabId);
}

private async _tryReattach(tabId: number): Promise<void> {
if (this._reattachAborted(tabId))
return;
let tab: chrome.tabs.Tab | undefined;
try {
tab = await chrome.tabs.get(tabId);
} catch {
this._pendingReattach.delete(tabId);
this._checkLastTabDetached();
return;
}
if (this._reattachAborted(tabId))
return;
if (this._attachedTabs.has(tabId)) {
this._pendingReattach.delete(tabId);
return;
}
this.attachTab(tab);
setTimeout(() => {
if (this._reattachAborted(tabId))
return;
this._pendingReattach.delete(tabId);
if (!this._attachedTabs.has(tabId))
this._checkLastTabDetached();
}, REATTACH_VERIFY_MS);
}

// Returns the tabId an event refers to, for filtering by _attachedTabs.
private _tabIdForEventArgs(fullMethod: string, args: any[]): number | undefined {
switch (fullMethod) {
Expand Down
1 change: 1 addition & 0 deletions packages/isomorphic/trace/traceModernizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export class TraceModernizer {
const existing = this._actionMap.get(event.callId);
existing!.inputSnapshot = event.inputSnapshot;
existing!.point = event.point;
existing!.box = event.box;
break;
}
case 'log': {
Expand Down
5 changes: 0 additions & 5 deletions packages/playwright-client/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18761,11 +18761,6 @@ export interface Screencast {
height: number;
};
quality?: number;
annotate?: {
duration?: number;
position?: 'top-left' | 'top' | 'top-right' | 'bottom-left' | 'bottom' | 'bottom-right';
fontSize?: number;
};
}): Promise<Disposable>;
/**
* Removes action decorations.
Expand Down
4 changes: 2 additions & 2 deletions packages/playwright-core/browsers.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
},
{
"name": "firefox",
"revision": "1539",
"revision": "1540",
"installByDefault": true,
"browserVersion": "153.0",
"title": "Firefox"
},
{
"name": "webkit",
"revision": "2346",
"revision": "2349",
"installByDefault": true,
"revisionOverrides": {
"mac14": "2251",
Expand Down
4 changes: 3 additions & 1 deletion packages/playwright-core/src/client/browserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,11 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel>
this._closingStatus = 'closing';
await this.request.dispose(options);
await this._instrumentation.runBeforeCloseBrowserContext(this);
await this.tracing._exportAllHars();
const harError = await this.tracing._exportAllHars().catch(e => e);
await this._channel.close(options, kNoTimeout);
await this._closedPromise;
if (harError)
throw harError;
}

async _enableRecorder(params: channels.BrowserContextEnableRecorderParams, eventSink?: RecorderEventSink) {
Expand Down
7 changes: 5 additions & 2 deletions packages/playwright-core/src/server/browserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,15 +554,16 @@ export abstract class BrowserContext<EM extends EventMap = EventMap> extends Sdk
}

async close(progress: Progress, options: { reason?: string }) {
let flushError: Error | undefined;
if (this._closedStatus === 'open') {
if (options.reason)
this._closeReason = options.reason;
this.emit(BrowserContext.Events.BeforeClose);
this._closedStatus = 'closing';

await progress.race(Promise.all([
this.tracing.flush(),
this.fetchRequest.tracing().flush(),
this.tracing.flush().catch(e => flushError = flushError ?? e),
this.fetchRequest.tracing().flush().catch(e => flushError = flushError ?? e),
]));
await progress.race(Promise.all(this.pages().map(page => page.screencast.handlePageOrContextClose())));

Expand All @@ -587,6 +588,8 @@ export abstract class BrowserContext<EM extends EventMap = EventMap> extends Sdk
this._didCloseInternal();
}
await this._closePromise;
if (flushError)
throw flushError;
}

async newPage(progress: Progress, forStorageState?: boolean): Promise<Page> {
Expand Down
Loading
Loading