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

Odd JavaScript Errors in Developer Tools #12217

Closed
jonathansampson opened this issue Oct 20, 2020 · 2 comments · Fixed by brave/brave-core#8894
Closed

Odd JavaScript Errors in Developer Tools #12217

jonathansampson opened this issue Oct 20, 2020 · 2 comments · Fixed by brave/brave-core#8894

Comments

@jonathansampson
Copy link
Contributor

Description

Users observing the developer tools may see strange JavaScript errors, potentially unrelated to any of their own code. For example:

VM91284:1 Uncaught TypeError: Cannot read property 'innerText' of null
    at <anonymous>:1:15

When the user clicks to examine the code which raised the exception, they see only the following:

document.body.innerText

Alternatively, they may see the following:

TypeError: Cannot read property 'requestContent' of undefined

Steps to Reproduce

Note: This issue is not very easy to reproduce; there definitely appears to be a race condition involved.

  1. Navigate to https://sampson.codes/brave/bugs/innerText-of-null/
  2. Open developer tools, and enable break on exception
  3. Using CMD|Ctrl + R, refresh the page over and over until the page halts on an exception

Actual result:

Exceptions are raised by code other than the user's.

Expected result:

No exceptions are raised by any code other than the user's.

Reproduces how often:

Intermittent. Somewhat difficult to reproduce.

Brave version (brave://version info)

Brave 1.15.75 Chromium: 86.0.4240.99 (Official Build) (64-bit)
Revision 002668237e13d38aabd6d11c2d216dd22b736ff2-refs/branch-heads/4240@{#1229}

Version/Channel Information:

  • Can you reproduce this issue with the current release? Yes
  • Can you reproduce this issue with the beta channel? Yes
  • Can you reproduce this issue with the nightly channel? Yes

Other Additional Information:

  • Does the issue resolve itself when disabling Brave Shields? No
  • Does the issue resolve itself when disabling Brave Rewards? Yes
  • Is the issue reproducible on the latest version of Chrome? No

Miscellaneous Information:

The test-URL above is not always quick to produce the error. @jonathansampson has another URL, which can be shared privately via Slack. If you're working on this, and would like a more consistent endpoint to test, please ping him.

@rebron rebron added feature/dev-tools intermittent-issue priority/P5 Not scheduled. Don't anticipate work on this any time soon. labels Jan 25, 2021
@jonathansampson
Copy link
Contributor Author

This code appears all throughout the Chromium codebase, but it looks like this particular instance is coming from an attempt to leverage the dom_distiller for page classification.

Source: /browser/brave_ads/ads_tab_helper.cc

void AdsTabHelper::RunIsolatedJavaScript(
    content::RenderFrameHost* render_frame_host) {
  DCHECK(render_frame_host);

  dom_distiller::RunIsolatedJavaScript(
      render_frame_host, "new XMLSerializer().serializeToString(document)",
      base::BindOnce(&AdsTabHelper::OnJavaScriptHtmlResult,
                     weak_factory_.GetWeakPtr()));

  dom_distiller::RunIsolatedJavaScript(
      render_frame_host, "document.body.innerText",
      base::BindOnce(&AdsTabHelper::OnJavaScriptTextResult,
                     weak_factory_.GetWeakPtr()));
}

I suspect there is no body element at times, which causes the error. If this is the case, it may be appropriate to instead use optional chaining, like document?.body?.innerText.

@stephendonner
Copy link

stephendonner commented Jun 1, 2021

Despite being unable to reproduce this using 1.15.75 (yet), I'm verifying using the inline testplan here, with build

Brave 1.27.33 Chromium: 91.0.4472.77 (Official Build) nightly (x86_64)
Revision 1cecd5c8a856bc2a5adda436e7b84d8d21b339b6-refs/branch-heads/4472@{#1246}
OS macOS Version 11.4 (Build 20F71)

At the very least:

  1. the changes are inclusive and minimal
  2. I can't reproduce the problem with this build, regardless, so we should be good
example example
Screen Shot 2021-06-01 at 1 38 58 PM Screen Shot 2021-06-01 at 1 39 04 PM

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

Successfully merging a pull request may close this issue.

5 participants