fix(exposeFunction): exposeFunction should not leak client side BindingCalls (#28163)

This should already make it a bit better. There is more going on tho.

https://github.com/microsoft/playwright/issues/28146
This commit is contained in:
Max Schmitt 2023-11-15 17:15:25 +01:00 committed by GitHub
parent 557f3afd74
commit b66839b039
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 85 additions and 0 deletions

View file

@ -364,9 +364,11 @@ export class BindingCallDispatcher extends Dispatcher<{ guid: string }, channels
async resolve(params: channels.BindingCallResolveParams, metadata: CallMetadata): Promise<void> {
this._resolve!(parseArgument(params.result));
this._dispose();
}
async reject(params: channels.BindingCallRejectParams, metadata: CallMetadata): Promise<void> {
this._reject!(parseError(params.error));
this._dispose();
}
}

View file

@ -256,6 +256,89 @@ it('should work with the domain module', async ({ browserType, server, browserNa
throw err;
});
it('exposeFunction should not leak', async ({ page, expectScopeState, server }) => {
await page.goto(server.EMPTY_PAGE);
let called = 0;
await page.exposeFunction('myFunction', () => ++called);
for (let i = 0; i < 10; ++i)
await page.evaluate(() => (window as any).myFunction({ foo: 'bar' }));
expect(called).toBe(10);
expectScopeState(page, {
'_guid': '',
'objects': [
{
'_guid': 'android',
'objects': [],
},
{
'_guid': 'browser-type',
'objects': [],
},
{
'_guid': 'browser-type',
'objects': [],
},
{
'_guid': 'browser-type',
'objects': [
{
'_guid': 'browser',
'objects': [
{
'_guid': 'browser-context',
'objects': [
{
'_guid': 'page',
'objects': [
{
'_guid': 'frame',
'objects': [],
},
{
'_guid': 'request',
'objects': [
{
'_guid': 'response',
'objects': [],
},
],
},
],
},
{
'_guid': 'request-context',
'objects': [],
},
{
'_guid': 'tracing',
'objects': [],
},
],
},
],
},
],
},
{
'_guid': 'electron',
'objects': [],
},
{
'_guid': 'localUtils',
'objects': [],
},
{
'_guid': 'Playwright',
'objects': [],
},
{
'_guid': 'selectors',
'objects': [],
},
],
});
});
function compareObjects(a, b) {
if (a._guid !== b._guid)
return a._guid.localeCompare(b._guid);