Encountering the error message "org.openqa.selenium.JavascriptException: javascript error: eval is disabled" when attempting to conduct accessibility testing with Axe-Core

My current project involves conducting accessibility testing using the Axe-Core tool with Java as the programming language. While I have successfully obtained results from many pages in my application, I encountered an error on one specific page:

 org.openqa.selenium.JavascriptException: javascript error: eval is disabled
(Session info: chrome=81.0.4044.138)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'XXXX', ip: 'XXXX', os.name: 'Windows 10', os.arch: 'amd64', 
os.version: '10.0', java.version: '1.8.0_131'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 81.0.4044.138, chrome: 
{chromedriverVersion: 81.0.4044.138 (8c6c7ba89cc9..., userDataDir: C:\Users\NASEEM~1.AHM\AppDa...}, 
goog:chromeOptions: {debuggerAddress: localhost:52030}, javascriptEnabled: true, 
networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, 
proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, 
pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:virtualAuthenticators: true}
Session ID: cbdfe9de190b8224da1ec675bef90966

The error occurs within the following code snippet:

 JSONObject responseJSON = new AXE.Builder(driver, scriptUrl).analyze(); 

This issue specifically arises when running the test in the Chrome browser. Surprisingly, when executing the same code in Firefox, it runs smoothly without any hiccups.

Is there anything else that I should consider adding while running the test? Are there any desired capabilities that I need to include?

Your suggestions would be highly appreciated.

Answer №1

It seems likely that the error you are encountering is due to a content security policy implemented on the website you are testing.

A Content Security Policy (CSP) is put in place by website owners to protect users from any malicious third-party scripts, CSS or images being injected into their site. Any content not explicitly allowed in the CSP will be blocked.

One of the restrictions within a CSP is blocking the use of JavaScript's eval function, which appears to be necessary for your program.

To resolve this issue, the site owner would need to specifically permit the use of eval on their site by adding unsafe-eval as a rule in their CSP configuration.

As stated on the linked page about CSP:

'unsafe-eval'

Allows the use of eval() and similar methods for creating code from strings. Single quotes must be included.

If you suspect the CSP is causing the problem, you can test it on another strict CSP site like mine at .

Update after discussions

Although I correctly identified the issue, the actual cause was different than initially thought.

The website was preventing the use of window.eval, effectively disabling it. This behavior can be seen in a simple example demonstrated in the provided fiddle.

Your options for addressing this include rewritting Axe-Core to avoid the use of eval, as it may inject this into the Window object being tested.

If others face the same problem, one potential solution could involve replacing the problematic script with a version that overrides

window.eval</code to allow the script to run. However, if they are also using a CSP that blocks <code>window.eval
, injecting such a script may not be feasible.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

There seems to be a malfunction in the PHP controller causing issues with the functionality

Currently, I am utilizing jQuery and PHP for my project. In the controller, I have integrated AJAX functionality. Upon the initial click action, the result is successfully retrieved (the current "show more button" is hidden and a new "show more button" is ...

Ruby Capybara::ExpectationNotMet: Selenium session reset took too long to complete Failure/Error

I am facing recurring issues on my CI server with Selenium session not resetting properly. This problem does not occur when running tests locally, only on the CI server. The versions I am using are Capybara 2.18.0, rspec 3.7.0, selenium-webdriver 3.9.0, a ...

Transform an array of objects into an object of objects while maintaining the interior structure

I am searching for a specific solution that I have not come across yet. If such a solution exists, I would greatly appreciate a link to it. Currently, my code looks like this: const obj = {"key": [ { "name": { "companyName": "Something" } }, { "otherT ...

What is the best method for resizing an SVG according to the size of my website's window?

I am attempting to implement a scalable settings icon SVG file that adjusts based on the window width. My approach involved creating a JavaScript function that alters the element's dimensions according to the window size, but unfortunately, this metho ...

Is it possible to execute a Selenium WebDriver Jar file from a Linux command line? If so, what are the steps

After attempting to run the command java -jar samplewebdrivercode.jar, I encountered a Manifest error. Is it feasible to accomplish this task? ...

replace the tsconfig.json file with the one provided in the package

While working on my React app and installing a third-party package using TypeScript, I encountered an error message that said: Class constructor Name cannot be invoked without 'new' I attempted to declare a variable with 'new', but tha ...

Loading your NextJS page with a full-page loader

I am looking to create a full-page loader for my NextJS app, similar to this example: https://jsfiddle.net/yaz9x42g/8/. The idea is that once the content is loaded, it should be revealed in a visually appealing way. I want to build a reusable component tha ...

What is the best way to utilize Object.keys for formatting incoming data?

Here is the data I have: const langs = { en: ['One', 'description'], pl: ['Jeden', 'opis'], }; I want to convert it into this format: const formattedData = { name: { en: "One", ...

Obtain the date value in the format of month/day/year

How can I retrieve the date from 2 months ago and format it as MM/DD/YYYY? I tried this code snippet, but it's returning a value in the format "Tue Feb 11 14:30:42 EST 2014". var currentDate = new Date(); currentDate.setMonth(currentDate.getMonth() ...

Error encountered in Azure DevOps when attempting to start ChromeDriver 2.36.540470 on a designated port, restricting connections to only local

Encountering an Azure DevOps error when starting ChromeDriver 2.36.540470 on a port, restricting connections to local only. This is causing issues with executing the build on Azure DevOps, even though it runs successfully on the local system. The followin ...

Dragging and dropping a slider bar in Python using Selenium is possible, even without the need for

Currently, I am working on test automation using seleniumeasy.com. My challenge lies in the drag and drop slider functionality where I am struggling to adjust the bar value from 10 to 80. Here's the code snippet I tried but unfortunately failed: drag ...

What could be causing the Uncaught Error to persist even after using .catch()?

Check out this code snippet: function pause(ms:number) { return new Promise((resolve:any,reject:any) => setTimeout(resolve,ms)) } async function throwError(): Promise<void> { await pause(2000) console.log("error throw") throw new ...

Challenges Arising from Modifying State Array within React Component

Description: I have encountered a challenge when trying to update a state array within a React component, especially when dealing with 2D arrays. Despite following the recommended approach of immutably updating state using setState, I am experiencing diff ...

Troubleshooting tip for React JS: encountered an unexpected object error when trying to import components

I've been working on building a react app with Create React App, and everything was going smoothly until I encountered a frustrating error message: Element type is invalid: expected a string (for built-in components) or a class/function (for composite ...

Retrieve the Windows Operating System Language Configuration Data

Is there a way to detect the list separator delimiter in client machines' language settings? I am working on a project website that exports reports in CSV format using PHP, Javascript, and JQuery. Currently, we use a comma as the delimiter for the CSV ...

I am experiencing difficulties with rendering highcharts to my div

I am currently working on integrating a highchart demo into a backbone.js widget. The HighChart Demo is not rendering properly within my widget, even though the template generates everything else correctly. It seems that there might be an issue with highc ...

Ruby on Rails allows for the selection of values in a dropdown menu to trigger the visibility of different sections of HTML

As a newcomer to Rails, I was able to successfully implement the onclick function for a f.checkbox element. Now, my challenge lies in achieving a similar functionality for a f.select element within a _form. Below is the code snippet that works for a chec ...

Issues with the visibility of React Bootstrap components

I'm troubleshooting an issue with the carousel on my website. When I try to load the page, the carousel appears blank. To set up the carousel, I used npm to install react-bootstrap. The carousel code can be found at . Upon checking the web console, ...

Developing a modal with various hyperlinks

I'm currently working on a website that features multiple news articles, each linking to a separate page. Is it possible to use modal windows to have the articles pop up on the same page instead of opening in a new window? If so, I would greatly appre ...

What is causing the failure in retrieving the smallest number from this array?

The maximum value should be 9.99, and the minimum value should be 6.88 let arr = [["2019","00","01", 9.99], ["2018","00","01", 9.32], ["2017","00","01", 6.88]] let max = Math.max(Number(...arr.map((o) => { return o[3] }))); //9.99 let min = Math.mi ...