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

Uncatchable exception occurs in analyze function #768

Open
1 task done
scribabble opened this issue Jul 13, 2023 · 3 comments
Open
1 task done

Uncatchable exception occurs in analyze function #768

scribabble opened this issue Jul 13, 2023 · 3 comments

Comments

@scribabble
Copy link

Product

playwright

Product Version

4.7.3

Latest Version

  • I have tested the issue with the latest version of the product

Issue Description

Expectation

I expect that if I wrap the call to the analyze function in a try catch statement or use a promise.catch, I would be able to catch any exception that is thrown by the function.

Actual

There are certain cases that can cause an uncatchable exception to be thrown by the function.

How to Reproduce

import AxeBuilder from "@axe-core/playwright";
import playwright = require("playwright");

process.on("uncaughtException", (err) => {
  console.error("An uncaught exception occurred: ", err);

  switch (err.message) {
    case "page.evaluate: Execution context was destroyed, most likely because of a navigation":
      console.error(
        "The page execution context was destroyed. Attempting to continue..."
      );
      break;
    default:
      process.exit(1);
  }
});

(async () => {
  const browser = await playwright.chromium.launch({ headless: false });
  const context = await browser.newContext();
  const page = await context.newPage();
  console.info(`Loading page...`);
  page.goto("https://youtube.com");

  try {
    console.info(`Analyzing page...`);
    await new AxeBuilder({ page }).analyze().catch((e) => {
      console.error(`Error occurred when analyzing page: ${e}`);
    });
  } catch (e) {
    console.error(`Error occurred when analyzing page: ${e}`);
  }

  console.info(`Loading page new page...`);
  await page.goto("https://google.com");

  await browser.close();
})();

Example output

Debugger attached.
Loading page...
Analyzing page...
An uncaught exception occurred:  page.evaluate: Execution context was destroyed, most likely because of a navigation
    at AxeBuilder.analyze (/Users/nscribano/Developer/go/src/bitbucket.org/atlassian/axe-scanner/node_modules/@axe-core/playwright/dist/index.js:236:10)
    at /Users/nscribano/Developer/go/src/bitbucket.org/atlassian/axe-scanner/dist/src/index.js:26:50 {
  name: 'Error'
}
The page execution context was destroyed. Attempting to continue...
Error occurred when analyzing page: Error: page.evaluate: Execution context was destroyed, most likely because of a navigation
Loading page new page...
Waiting for the debugger to disconnect...

Additional context

The "how to reproduce" code is a bit convoluted because the exception would not occur if I were to await the page.goto("https://youtube.com"); call. However, I have seen this bug happen a handful of times in a real environment where I have a service that is iterating across URLs and scanning them with axe-core/playwright. That bug is difficult to recreate consistently, but the code I've included above has the same effect. Either way, I would expect to be able to catch the exception that happens.

@straker
Copy link
Contributor

straker commented Jul 13, 2023

Thanks for the issue. We'll try to update the code to better handle this scenario.

@KuSh
Copy link
Contributor

KuSh commented May 14, 2024

Hi, could be fixed by #1063 at least it seems related

@scribabble
Copy link
Author

@KuSh I believe you're right. I think your PR may have very likely addressed this issue.

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

No branches or pull requests

3 participants