Topic: https://intoli.com/blog/javascript-injection/
hide preview

What's next? verify your email address for reply notifications!

vojelo 6y, 123d ago

it looks like General Method (with Extension) doesn't work. After page loaded the navigator.webdriver is true, although in extension's function it was false.

remark link
hide preview

What's next? verify your email address for reply notifications!

evan 6y, 90d ago [edited]

You're likely running into an extension sandboxing issue here. The content script context will be sandboxed from the page context. You'll need to inject a script tag into the page's DOM to evaluate code outside of the sandbox. You can use methods like Document.createElement() and Node.appendChild() to create and inject the script tag.

Edit: See Breaking Out of the Chrome/WebExtension Sandbox for a more detailed solution.

hide preview

What's next? verify your email address for reply notifications!

GwkoDL1P 6y, 103d ago [edited]

For Headless Chrome with Selenium there is a solution a bit simpler than a WebExtension with Page.addScriptToEvaluateOnNewDocument method (see this answer on SO https://stackoverflow.com/a/47298910)

remark link
hide preview

What's next? verify your email address for reply notifications!

evan 6y, 90d ago

Thanks, that's a great trick!

hide preview

What's next? verify your email address for reply notifications!

evan 6y, 37d ago

Some people had been running into sandboxing issues when using WebExtensions to inject JavaScript. We just published an article called Breaking Out of the Chrome/WebExtension Sandbox which explains how to get around the context isolation.

hide preview

What's next? verify your email address for reply notifications!

unverified 5y, 189d ago

The best guide I found in a week. Thank you.

hide preview

What's next? verify your email address for reply notifications!

unverified 5y, 154d ago

We can successfully use Chrome extensions now with --> options.addExtensions(await encode("chrome_ext/My-downloaded-extension.crx"). For the extension to work, I simply base64 encode the extension.

I would love to see an updated version of these articles using Chrome extensions. They are fantastic! Great job, Evan!

hide preview

What's next? verify your email address for reply notifications!

unverified 5y, 144d ago

well done!

hide preview

What's next? verify your email address for reply notifications!