mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(remote): unregister selectors after client disconnect (#6195)
This commit is contained in:
parent
ce0098d9eb
commit
ce96914292
@ -21,6 +21,7 @@ import { DispatcherConnection, DispatcherScope } from '../dispatchers/dispatcher
|
||||
import { PlaywrightDispatcher } from '../dispatchers/playwrightDispatcher';
|
||||
import { createPlaywright } from '../server/playwright';
|
||||
import { gracefullyCloseAll } from '../server/processLauncher';
|
||||
import { serverSelectors } from '../server/selectors';
|
||||
|
||||
const debugLog = debug('pw:server');
|
||||
|
||||
@ -37,13 +38,17 @@ export class PlaywrightServer {
|
||||
private _delegate: PlaywrightServerDelegate;
|
||||
|
||||
static async startDefault(port: number = 0): Promise<string> {
|
||||
const cleanup = async () => {
|
||||
await gracefullyCloseAll().catch(e => {});
|
||||
serverSelectors.unregisterAll();
|
||||
};
|
||||
const delegate: PlaywrightServerDelegate = {
|
||||
path: '/ws',
|
||||
allowMultipleClients: false,
|
||||
onClose: gracefullyCloseAll,
|
||||
onClose: cleanup,
|
||||
onConnect: (rootScope: DispatcherScope) => {
|
||||
new PlaywrightDispatcher(rootScope, createPlaywright());
|
||||
return () => gracefullyCloseAll().catch(e => {});
|
||||
return cleanup;
|
||||
},
|
||||
};
|
||||
const server = new PlaywrightServer(delegate);
|
||||
|
||||
@ -55,6 +55,10 @@ export class Selectors {
|
||||
this._engines.set(name, { source, contentScript });
|
||||
}
|
||||
|
||||
unregisterAll() {
|
||||
this._engines.clear();
|
||||
}
|
||||
|
||||
async _query(frame: frames.Frame, selector: string, scope?: dom.ElementHandle): Promise<dom.ElementHandle<Element> | null> {
|
||||
const info = this._parseSelector(selector);
|
||||
const context = await frame._context(info.world);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user