Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] exposeBinding does not work with content scripts in Chromium #12017

Closed
Banou26 opened this issue Feb 11, 2022 · 4 comments
Closed

[BUG] exposeBinding does not work with content scripts in Chromium #12017

Banou26 opened this issue Feb 11, 2022 · 4 comments

Comments

@Banou26
Copy link

Banou26 commented Feb 11, 2022

Context:

  • Playwright Version: ^1.18.0
  • Operating System: Windows
  • Node.js version: 17.1.0
  • Browser: Chromium

Code Snippet

// index.js
(async () => {
  const { chromium } = require('playwright')
  const pathToExtension = require('path').join(__dirname, './ext')
  const userDataDir = require('path').join(__dirname, './tmp/test-user-data-dir')
  const browserContext = await chromium.launchPersistentContext(userDataDir, {
    headless: false,
    args: [
      `--disable-extensions-except=${pathToExtension}`,
      `--load-extension=${pathToExtension}`
    ]
  })
  const page = await browserContext.newPage()

  await page.exposeBinding('foo', async (_, data) => {
    console.log('data', data)
  })
  await page.goto('https://google.com')
  await browserContext.close()
})()

Having the extension content-script context code call exposed functions doesn't work

// content-script.js
foo() // throws Uncaught Error: Invalid arguments: should be exactly one string.
foo({}) // throws Uncaught Error: Invalid arguments: should be exactly one string.
foo(1) // throws Uncaught Error: Invalid arguments: should be exactly one string.

foo('') // crashes Playwright

Describe the bug

Calling exposed functions from an extension context doesn't work as expected.
It either throws Uncaught Error: Invalid arguments: should be exactly one string.

or crashes playwright by throwing

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at Function.dispatch (C:\Users\Banou\Desktop\playwright-ext\node_modules\playwright-core\lib\server\page.js:579:14)
    at Page._onBindingCalled (C:\Users\Banou\Desktop\playwright-ext\node_modules\playwright-core\lib\server\page.js:251:23)
    at FrameSession._onBindingCalled (C:\Users\Banou\Desktop\playwright-ext\node_modules\playwright-core\lib\server\chromium\crPage.js:849:37)
@pavelfeldman pavelfeldman changed the title [BUG] WebExtension interacting with exposeBinding crashes playwright [BUG] exposeBinding does not work with content scripts in Chromium Feb 11, 2022
@aslushnikov aslushnikov added v1.21 and removed v1.20 labels Mar 1, 2022
@gsidsid
Copy link

gsidsid commented Sep 6, 2022

+1 Have been waiting for a fix on this as well

@LanderBeeuwsaert
Copy link

We're experiencing this too when we try to change from launching our tests & playwright with:
"node --experimental-loader esbuild-node-loader ./parallel-test.ts"
to
"npx tsx ./parallel-test.ts"
when calling in the browser javascript code the exposed binding it gives the error

@pavelfeldman
Copy link
Member

Why was this issue closed?

Thank you for your contribution to our project. This issue has been closed due to its limited upvotes and recent activity, and insufficient feedback for us to effectively act upon. Our priority is to focus on bugs that reflect higher user engagement and have actionable feedback, to ensure our bug database stays manageable.

Should you feel this closure was in error, please create a new issue and reference this one. We're open to revisiting it given increased support or additional clarity. Your understanding and cooperation are greatly appreciated.

@James4Ever0
Copy link

James4Ever0 commented Nov 8, 2023

+1 for reopening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants