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

How to use "PageAddScriptToEvaluateOnNewDocument"? #44

Closed
pu369 opened this issue May 29, 2020 · 3 comments
Closed

How to use "PageAddScriptToEvaluateOnNewDocument"? #44

pu369 opened this issue May 29, 2020 · 3 comments
Labels
question Questions related to rod

Comments

@pu369
Copy link

pu369 commented May 29, 2020

Could you give an example code of "PageAddScriptToEvaluateOnNewDocument"?
I want to change the value of "window.navigator.webdriver"!

The next line will cause automation to stop
page.Eval(() => Object.defineProperties(navigator, 'webdriver', {get: () => undefined}))

@pu369 pu369 added the question Questions related to rod label May 29, 2020
@ysmood
Copy link
Member

ysmood commented May 29, 2020

func Example () {
    page := browser.Page("")

    proto.PageAddScriptToEvaluateOnNewDocument{
        Source: `console.log("ok")`
    }.Call(page)

    page.Navigate("https://github.com")
}

@ysmood
Copy link
Member

ysmood commented May 29, 2020

@pu369 your code itself is not valid js, you'd better check the error output and fix your syntax first. The code below works fine for me.

page.Eval(`() => Object.defineProperties(navigator, {
	webdriver: {
		get: () => undefined
	}
})`)

@ysmood ysmood closed this as completed May 29, 2020
@pu369
Copy link
Author

pu369 commented Jun 1, 2020

@ysmood thank you so much.

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

No branches or pull requests

2 participants