Skip to content

Commit

Permalink
fix(remote): unregister selectors after client disconnect (#6195)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgozman committed Apr 16, 2021
1 parent ce0098d commit ce96914
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/remote/playwrightServer.ts
Expand Up @@ -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');

Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/server/selectors.ts
Expand Up @@ -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);
Expand Down

0 comments on commit ce96914

Please sign in to comment.