You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Im kind of new to github, so let me know if I'm doing this wrong.
page.evaluate() function is not returning anything when using rebrowser-patches and context isolation is activated in any way.
The script does not continue until the method returns something, causing the code to stall.
Both addBinding and enableDisable gives me the same error, but its not a problem while using the original playwright nor when
using this setting:
os.environ["REBROWSER_PATCHES_RUNTIME_FIX_MODE"] = "0"
For the methods that work fine, the following line would print out True, whilst with rebrowser-playwright-python nothing gets printed or returned.
print(await page.evaluate("window.dummyFn()"))
This causes me to believe it has to do with context isolation.
To reproduce the issue:
I used the drop-in method for rebrowser-playwright-python using this installation "pip install rebrowser-playwright"
Semi-minimum Viable Code to reproduce:
import os
import asyncio
from rebrowser_playwright.async_api import async_playwright
# Set environment variable to use addBinding to access the main context
os.environ["REBROWSER_PATCHES_RUNTIME_FIX_MODE"] = "addBinding" # Allow access to main context although it's also on by default
os.environ["REBROWSER_PATCHES_DEBUG"] = "1" # Enable debugging messages to see more logs
# Custom User-Agent for Chromium (can be any valid user-agent string)
user_agent = (
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/91.0.4472.124 Safari/537.36"
)
async def run():
async with async_playwright() as p:
# Launch Google Chrome with minimal args
browser = await p.chromium.launch(
headless=False,
channel = "chrome",
args=["--disable-blink-features=AutomationControlled"]
)
# Create a new context with the specified user-agent
context = await browser.new_context(
user_agent=user_agent # Apply the custom user-agent
)
# Create a new page within the context
page = await context.new_page()
# Go to the bot detector page
await page.goto("https://bot-detector.rebrowser.net/") # Visit the bot detector
# Trigger the dummyFn test
print("Running dummyFn test...")
try:
print(await page.evaluate("window.dummyFn()")) # Execute dummyFn in the main context
except Exception as e:
print(f"Error executing dummyFn: {e}")
# Pause for inspection (optional)
await page.pause()
# Run the script with asyncio.run() for proper asynchronous execution
asyncio.run(run())
These are the results. Interesting to see that the "dummyFn" test actually still passes. But the code doesn't continue to run, so can't run more tests.
Another thing that might be useful is that it actually fails the sourceUrlLeak, mainWorldExecution and exposeFunctionLeak tests. To test this they had to be the first evaluate function in the script as it will not run after the first one.
My code for running said tests
# Source URL Leak test
print("Running sourceUrlLeak test...")
try:
await page.evaluate("document.getElementById('detections-json')")
print("sourceUrlLeak test passed")
except Exception as e:
print(f"Error executing sourceUrlLeak: {e}")
# Main world execution test
print("Running mainWorldExecution test...")
try:
await page.evaluate("document.getElementsByClassName('div')")
print("mainWorldExecution test passed")
except Exception as e:
print(f"Error executing mainWorldExecution: {e}")
# Expose function leak test
print("Running exposeFunctionLeak test...")
try:
await page.expose_function('exposedFn', lambda: print('exposedFn call'))
print("exposeFunctionLeak test passed")
except Exception as e:
print(f"Error executing exposeFunctionLeak: {e}")
But I understand that some of these are still waiting for a patch for the playwright-python version.
Which I'm very keenly waiting for by the way.
The text was updated successfully, but these errors were encountered:
Thanks for such a detailed bug report. I see you have REBROWSER_PATCHES_DEBUG enabled, so what does it say in the console logs right when page.evaluate is called?
then I seem to be passing all the tests on bot-detector.rebrowser.net (except mainWorldExecution as it's not fixed yet for playwright).
Does this mean that any javascript being run through the browser using the ".page" object is currently not returning any values?
I wonder what other side-effects this might have for other functions I might be using.
Im kind of new to github, so let me know if I'm doing this wrong.
page.evaluate() function is not returning anything when using rebrowser-patches and context isolation is activated in any way.
The script does not continue until the method returns something, causing the code to stall.
Both addBinding and enableDisable gives me the same error, but its not a problem while using the original playwright nor when
using this setting:
os.environ["REBROWSER_PATCHES_RUNTIME_FIX_MODE"] = "0"
For the methods that work fine, the following line would print out True, whilst with rebrowser-playwright-python nothing gets printed or returned.
print(await page.evaluate("window.dummyFn()"))
This causes me to believe it has to do with context isolation.
To reproduce the issue:
I used the drop-in method for rebrowser-playwright-python using this installation "pip install rebrowser-playwright"
Semi-minimum Viable Code to reproduce:
These are the results. Interesting to see that the "dummyFn" test actually still passes. But the code doesn't continue to run, so can't run more tests.
Another thing that might be useful is that it actually fails the sourceUrlLeak, mainWorldExecution and exposeFunctionLeak tests. To test this they had to be the first evaluate function in the script as it will not run after the first one.
My code for running said tests
But I understand that some of these are still waiting for a patch for the playwright-python version.
Which I'm very keenly waiting for by the way.
The text was updated successfully, but these errors were encountered: