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

fix(codegen): document.documentElement is null on early navigation #33627

Merged
merged 3 commits into from
Nov 15, 2024

Conversation

mxschmitt
Copy link
Member

@mxschmitt mxschmitt commented Nov 15, 2024

This PR fixes the following when opening Codegen on https://primevue.org/inputnumber/:

VM26:921 Recorder::installListners install error TypeError: Cannot read properties of null (reading 'contains')
    at Highlight.install (<anonymous>:4742:56)
    at Recorder.installListeners (eval at extend (inputnumber/:5876:40), <anonymous>:919:22)
    at new Recorder (eval at extend (inputnumber/:5876:40), <anonymous>:890:10)
    at new PollingRecorder (eval at extend (inputnumber/:5876:40), <anonymous>:1322:22)
    at InjectedScript.extend (<anonymous>:5882:12)
    at eval (eval at evaluate (inputnumber/:234:30), <anonymous>:5:29)
    at UtilityScript.evaluate (<anonymous>:236:17)
    at UtilityScript.<anonymous> (<anonymous>:1:44)

In TypeScript this type is not nullable. This is working as intended from their side: microsoft/TypeScript#50078

Minimal Playwright repro script. This sometimes returns true and sometimes false.

import { chromium } from 'playwright';

(async () => {
  const check = async () => {
    const browser = await chromium.launch({ headless: false });
    const context = await browser.newContext();
    const page = await context.newPage();
    await page.goto('https://primevue.org/inputnumber/', {waitUntil: 'commit'});
    console.log(await page.evaluate(() => !!document.documentElement));

    await context.close();
    await browser.close();
  };
  while (true)
    await check();
})();

Contract-wise we have three users of Highlight::install:

  1. Recorder.installListeners
  2. Locator.highlight
  3. Locator.maskSelectors

The first one retries every couple of seconds. The other two we expect to be called after the navigation has happened IIUC.

I went over the rest of the code-base, there we usually check for null when interacting with document.documentElement.

@mxschmitt mxschmitt changed the title fix(codegen): document.documentElement is null / early navigation fix(codegen): document.documentElement is null on early navigation Nov 15, 2024

This comment has been minimized.

mxschmitt and others added 2 commits November 15, 2024 17:11
Co-authored-by: Dmitry Gozman <dgozman@gmail.com>
Signed-off-by: Max Schmitt <max@schmitt.mx>
@mxschmitt mxschmitt merged commit c81504c into microsoft:main Nov 15, 2024
28 of 29 checks passed
@mxschmitt mxschmitt deleted the documentElement-null branch November 15, 2024 16:14

This comment has been minimized.

mxschmitt added a commit that referenced this pull request Nov 15, 2024
Copy link
Contributor

Test results for "tests 1"

3 flaky ⚠️ [chromium-page] › page/page-event-request.spec.ts:138:3 › should report navigation requests and responses handled by service worker with routing @chromium-ubuntu-22.04-node18
⚠️ [chromium-page] › page/page-event-request.spec.ts:110:3 › should report navigation requests and responses handled by service worker @chromium-ubuntu-22.04-node22
⚠️ [chromium-library] › library/inspector/cli-codegen-java.spec.ts:49:5 › should print the correct context options when using a device @ubuntu-20.04-chromium-tip-of-tree

36892 passed, 650 skipped
✔️✔️✔️

Merge workflow run.

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

Successfully merging this pull request may close these issues.

2 participants