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

[rebrowser-playwright] Use directly rebrowser-playwright-core #74

Open
regseb opened this issue Dec 14, 2024 · 1 comment
Open

[rebrowser-playwright] Use directly rebrowser-playwright-core #74

regseb opened this issue Dec 14, 2024 · 1 comment

Comments

@regseb
Copy link

regseb commented Dec 14, 2024

In my project, I have playwright and rebrowser-playwright as dependencies. I have both dependencies, because I use one or the other as needed. But when both have the same version number: rebrowser-playwright doesn't work.

rebrowser-playwright has playwright-core dependency which is replaced by npm:rebrowser-playwright-core@~1.49.1. Due to a bug in npm, the playwright-core dependency overrides rebrowser-playwright-core.


  • package.json

    {
      "name": "testcase",
      "version": "1.0.0",
      "type": "module",
      "dependencies": {
        "playwright": "1.49.1",
        "rebrowser-playwright": "1.49.1"
      }
    }
  • index.js

    import { chromium } from "rebrowser-playwright";
    
    const browser = await chromium.launch();
    const context = await browser.newContext();
    const page = await browser.newPage();
    await page.goto("https://bot-detector.rebrowser.net/");
    
    process.env.REBROWSER_PATCHES_RUNTIME_FIX_MODE = "alwaysIsolated";
    await page.evaluate(() => document.getElementsByClassName("div"));
    delete process.env.REBROWSER_PATCHES_RUNTIME_FIX_MODE;
    
    const detections = await page.locator("#detections-json").inputValue();
    console.log(JSON.parse(detections).find((d) => "mainWorldExecution" === d.type));
    
    await context.close();
    await browser.close();
  1. npm install

  2. node index.js

    {
      type: 'mainWorldExecution',
      rating: 1,
      note: `You've called <code>document.getElementsByClassName()</code> in the main world. Use <a href="https://github.com/rebrowser/rebrowser-patches" target="_blank">rebrowser-patches</a> to run your scripts in an isolated world.`,
      debug: { args: [ 'div' ] },
      msSinceLoad: 29.3
    }

To get around this bug, rebrowser-playwright would have to use rebrowser-playwright-core directly as a dependency (and change the imports).

@nwebson
Copy link
Contributor

nwebson commented Dec 23, 2024

Very nice catch, thanks for reporting this.

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

No branches or pull requests

2 participants