Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

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

Dmitry Gozmance969142922d
diff --git a/src/remote/playwrightServer.ts b/src/remote/playwrightServer.ts
index b7ae6a6c6f..1ee420b456 100644
--- a/src/remote/playwrightServer.ts
+++ b/src/remote/playwrightServer.ts
@@ -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);
diff --git a/src/server/selectors.ts b/src/server/selectors.ts
index f241ff00a8..ce65805ae9 100644
--- a/src/server/selectors.ts
+++ b/src/server/selectors.ts
@@ -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);