Skip to content

Commit 64947f1

Browse files
authored
cherrypick(release-1.4): fix compatibility to the domain module (#3878)
Cherry-picking #3851 References #3848
1 parent 014096a commit 64947f1

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/client/channelOwner.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ export abstract class ChannelOwner<T extends channels.Channel = channels.Channel
6262
return obj.addListener;
6363
if (prop === 'removeEventListener')
6464
return obj.removeListener;
65+
if (prop === 'domain') // https://github.com/microsoft/playwright/issues/3848
66+
return obj.domain;
6567
return (params: any) => this._connection.sendMessageToServer(this._type, guid, String(prop), params);
6668
},
6769
});

test/channels.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,22 @@
1515
* limitations under the License.
1616
*/
1717

18+
import domain from 'domain';
19+
import { registerWorkerFixture } from '@playwright/test-runner';
1820
import { it, expect, options } from './playwright.fixtures';
1921
import type { ChromiumBrowser } from '..';
2022

23+
registerWorkerFixture('domain', async ({ }, test) => {
24+
const local = domain.create();
25+
local.run(() => { });
26+
let err;
27+
local.on('error', e => err = e);
28+
local.enter();
29+
await test(null);
30+
if (err)
31+
throw err;
32+
});
33+
2134
it('should work', async ({browser}) => {
2235
expect(!!browser['_connection']).toBeTruthy();
2336
});
@@ -144,6 +157,14 @@ it('should scope browser handles', async ({browserType, defaultBrowserOptions})
144157
await expectScopeState(browserType, GOLDEN_PRECONDITION);
145158
});
146159

160+
it('should work with the domain module', async ({ domain, browserType }) => {
161+
const browser = await browserType.launch();
162+
const page = await browser.newPage();
163+
const result = await page.evaluate(() => 1 + 1);
164+
expect(result).toBe(2);
165+
await browser.close();
166+
});
167+
147168
async function expectScopeState(object, golden) {
148169
golden = trimGuids(golden);
149170
const remoteState = trimGuids(await object._channel.debugScopeState());

test/playwright.fixtures.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ declare global {
4848
browserType: BrowserType<Browser>;
4949
browser: Browser;
5050
httpService: {server: TestServer, httpsServer: TestServer}
51+
domain: void;
5152
toImpl: (rpcObject: any) => any;
5253
}
5354
interface TestState {

0 commit comments

Comments
 (0)