Sunday, 9 May 2021

Firefox in Python Selenium: driver.execute_script gives "SecurityError: The operation is insecure"

I am using Selenium 3.141.0 with Python, and currently I'm running Firefox 88.0 and geckodriver 0.29.1.

Previously, I was able to run the below JavaScript execution to remove unwanted characters (in this case ®) from web pages, as demonstrated in this answer:

driver.execute_script("var replaced = $('body').html().replace(/(®)/g,''); $('body').html(replaced);")

However, at some point recently this does no longer work, giving the following error:

JavascriptException: Message: SecurityError: The operation is insecure.

Presumably, when updating Selenium, Firefox, or geckodriver, this function broke – unless there is something with the web page that I crawl (which is not mine) that has changed recently, that is making the script impossible to execute (I don't know what on the web page possibly would cause this).

What could be the reason behind this issue, and is it possible to "override" the SecurityError and execute the script?



from Firefox in Python Selenium: driver.execute_script gives "SecurityError: The operation is insecure"

No comments:

Post a Comment