mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(bidi): correctly serialize kPlaywrightBinding (#35783)
This commit is contained in:
parent
9b59a6aea6
commit
d170bbbcb9
@ -20,7 +20,7 @@ import { BrowserContext, assertBrowserContextIsNotOwned, verifyGeolocation } fro
|
|||||||
import * as network from '../network';
|
import * as network from '../network';
|
||||||
import { BidiConnection } from './bidiConnection';
|
import { BidiConnection } from './bidiConnection';
|
||||||
import { bidiBytesValueToString } from './bidiNetworkManager';
|
import { bidiBytesValueToString } from './bidiNetworkManager';
|
||||||
import { addMainBinding, BidiPage, kPlaywrightBindingChannel } from './bidiPage';
|
import { addMainBindingSource, BidiPage, kPlaywrightBindingChannel } from './bidiPage';
|
||||||
import * as bidi from './third_party/bidiProtocol';
|
import * as bidi from './third_party/bidiProtocol';
|
||||||
|
|
||||||
import type { RegisteredListener } from '../utils/eventsHelper';
|
import type { RegisteredListener } from '../utils/eventsHelper';
|
||||||
@ -238,7 +238,6 @@ export class BidiBrowserContext extends BrowserContext {
|
|||||||
|
|
||||||
// TODO: consider calling this only when bindings are added.
|
// TODO: consider calling this only when bindings are added.
|
||||||
private async _installMainBinding() {
|
private async _installMainBinding() {
|
||||||
const functionDeclaration = addMainBinding.toString();
|
|
||||||
const args: bidi.Script.ChannelValue[] = [{
|
const args: bidi.Script.ChannelValue[] = [{
|
||||||
type: 'channel',
|
type: 'channel',
|
||||||
value: {
|
value: {
|
||||||
@ -247,7 +246,7 @@ export class BidiBrowserContext extends BrowserContext {
|
|||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
await this._browser._browserSession.send('script.addPreloadScript', {
|
await this._browser._browserSession.send('script.addPreloadScript', {
|
||||||
functionDeclaration,
|
functionDeclaration: addMainBindingSource,
|
||||||
arguments: args,
|
arguments: args,
|
||||||
userContexts: [this._userContextId()],
|
userContexts: [this._userContextId()],
|
||||||
});
|
});
|
||||||
|
@ -328,7 +328,7 @@ export class BidiPage implements PageDelegate {
|
|||||||
// For non-persistent context, the main binding is installed during context creation.
|
// For non-persistent context, the main binding is installed during context creation.
|
||||||
if (this._browserContext._browserContextId)
|
if (this._browserContext._browserContextId)
|
||||||
return;
|
return;
|
||||||
const functionDeclaration = addMainBinding.toString();
|
const functionDeclaration = addMainBindingSource;
|
||||||
const args: bidi.Script.ChannelValue[] = [{
|
const args: bidi.Script.ChannelValue[] = [{
|
||||||
type: 'channel',
|
type: 'channel',
|
||||||
value: {
|
value: {
|
||||||
@ -572,9 +572,8 @@ export class BidiPage implements PageDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addMainBinding(callback: (arg: any) => void) {
|
export const addMainBindingSource =
|
||||||
(globalThis as any)[PageBinding.kPlaywrightBinding] = callback;
|
`function addMainBinding(callback) { globalThis['${PageBinding.kPlaywrightBinding}'] = callback; }`;
|
||||||
}
|
|
||||||
|
|
||||||
function toBidiExecutionContext(executionContext: dom.FrameExecutionContext): BidiExecutionContext {
|
function toBidiExecutionContext(executionContext: dom.FrameExecutionContext): BidiExecutionContext {
|
||||||
return executionContext.delegate as BidiExecutionContext;
|
return executionContext.delegate as BidiExecutionContext;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user