Skip to content

Commit

Permalink
Merge pull request #24477 from Marklb/marklb/fix-csp-error-in-a11y-addon
Browse files Browse the repository at this point in the history
Addon A11y: Avoid CSP issue
  • Loading branch information
valentinpalkovic authored Oct 27, 2023
2 parents 1b0ca54 + 55eccb3 commit 9925d3b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion code/addons/a11y/src/a11yRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,18 @@ const run = async (storyId: string) => {
}

const result = await axe.run(htmlElement, options);

// Axe result contains class instances, which telejson deserializes in a
// way that violates:
// Content Security Policy directive: "script-src 'self' 'unsafe-inline'".
const resultJson = JSON.parse(JSON.stringify(result));

// It's possible that we requested a new run on a different story.
// Unfortunately, axe doesn't support a cancel method to abort current run.
// We check if the story we run against is still the current one,
// if not, trigger a new run using the current story
if (activeStoryId === storyId) {
channel.emit(EVENTS.RESULT, result);
channel.emit(EVENTS.RESULT, resultJson);
} else {
active = false;
run(activeStoryId);
Expand Down

0 comments on commit 9925d3b

Please sign in to comment.