fix(remote): unregister selectors after client disconnect (#6195)

This commit is contained in:
Dmitry Gozman 2021-04-16 11:14:57 -07:00 committed by GitHub
parent ce0098d9eb
commit ce96914292
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -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);

View File

@ -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);