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

NoDriver: Page.addScriptToEvaluateOnNewDocument not working #1818

Open
GLorentz1 opened this issue Apr 4, 2024 · 1 comment
Open

NoDriver: Page.addScriptToEvaluateOnNewDocument not working #1818

GLorentz1 opened this issue Apr 4, 2024 · 1 comment

Comments

@GLorentz1
Copy link

First of all I apologize for bringing this discussion here, it was necessary as the NoDriver repo is limited to collaborators.

I am trying to run a simple script:

import nodriver as uc
from nodriver import cdp

config = uc.Config()
config.add_argument("--ignore-certificate-errors")
config.add_argument("--disable-web-security")

browser = await uc.start(config=config)
page = await browser.get()

script = "console.log('hi')"
await page.send(cdp.page.add_script_to_evaluate_on_new_document(source=script))
await page.get("https://www.google.com")
await page.sleep(10)

The page loads and there are no exceptions. However, nothing gets console.log'ed.
I have tried different methods (using browser.main_tab.send, or browser.connection.send instead of page.send) and scripts (like (() => {console.log('hi')})() or alert(1)) to no avail.

Any help would be appreciated. Thank you!

@ultrafunkamsterdam
Copy link
Owner

it works, but you forgot to run page.send(cdp.page.enable())

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