Skip to content

Commit 1462111

Browse files
PackageToJS: Fix missing await for page.exposeFunction
It caused concurrent calls to `exposeFunction` and resulted losing the function bindings after the playwright upgrade.
1 parent 8968aae commit 1462111

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Plugins/PackageToJS/Templates/bin/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Hint: This typically means that a continuation leak occurred.
116116
for (const [name, fn] of Object.entries(functions)) {
117117
// Bind the page context to each function if needed
118118
// The function can optionally use the page from its closure
119-
page.exposeFunction(name, fn);
119+
await page.exposeFunction(name, fn);
120120
}
121121
};
122122
}

Plugins/PackageToJS/Templates/test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,12 @@ Please run the following command to install it:
108108
page.on("console", (message) => {
109109
console.log(message.text());
110110
});
111-
111+
112+
let resolveExit = undefined;
112113
const onExit = new Promise((resolve) => {
113-
page.exposeFunction("exitTest", resolve);
114+
resolveExit = resolve;
114115
});
116+
await page.exposeFunction("exitTest", resolveExit);
115117
await page.goto(`http://localhost:${address.port}/test.browser.html`);
116118
const exitCode = await onExit;
117119
await browser.close();

0 commit comments

Comments
 (0)