How to determine why an alert dialog was displayed by Chrome?

565 views
Skip to first unread message

Ben Key

unread,
Oct 21, 2020, 9:10:57 AM10/21/20
to Chromium Extensions
I am trying to fix a bug in a Chrome extension. When the extension is installed an alert dialog containing the message "undefined" will be displayed seemingly at random. This does not happen when the extension is not installed.

There is not one call to alert, confirm, or prompt in the extension source code. How do I find out why the alert dialog is being displayed?

I have attempted adding the following code to one of the background scripts and to one of the content scripts.

    var originalWindowAlert = window.alert;
    window.alert = function() {
      console.trace();
      return originalWindowAlert.apply(window, arguments);
    }

I have confirmed that this technique works when used in a webpage, but it is not working for the extension.

I have also built Chromium from source code and I am able to reproduce it but so far I have not been able to figure out how to determine the origin of the alert dialog. I have set a breakpoint in the RenderFrameHostImpl::RunModalAlertDialog function but I see no way to determine what caused the breakpoint to be hit.

I am getting desperate.

PhistucK

unread,
Oct 21, 2020, 10:21:08 AM10/21/20
to Ben Key, Chromium Extensions
Wow, that is interesting.
Does it happen with every extension you install, or only with your own?
As an unpacked extension as well as an installed extension?

PhistucK


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/30fc04da-f047-4a69-b44f-425604a086d6n%40chromium.org.

Ben Key

unread,
Oct 21, 2020, 10:31:50 AM10/21/20
to Chromium Extensions, PhistucK, Chromium Extensions, Ben Key
It is only happening with this one extension. And it is happening when the extension is installed from the Chrome Web Store and when I use the Load Unpacked functionality.

PhistucK

unread,
Oct 21, 2020, 10:40:04 AM10/21/20
to Ben Key, Chromium Extensions
Did you try to reduce it (removing code until you are left with the minimal code that makes it happen)?

PhistucK

Ben Key

unread,
Oct 21, 2020, 10:55:58 AM10/21/20
to Chromium Extensions, PhistucK, Chromium Extensions, Ben Key
I do not know enough about extension development to even begin that approach. I do not know what I can remove without rendering the extension completely inoperative.

Is there a way  I can just set a breakpoint in Visual Studio in the Window.alert function so I can just look at the call stack window? That is what I really need to do.

PhistucK

unread,
Oct 21, 2020, 11:47:52 AM10/21/20
to Ben Key, Chromium Extensions
It is less about conserving the functionality and more about detecting the cause of the alert. Just duplicate the extension folder, load it as unpacked while disabling the original and start deleting code.
Once you figure out what causes it, you will understand whether it is a bug in your code, or a browser issue.

PhistucK

Ben Key

unread,
Oct 21, 2020, 12:02:44 PM10/21/20
to PhistucK, Chromium Extensions
Unfortunately, I do not know enough JavaScript to know what I can delete without causing compiler errors which would defeat the purpose of your approach.

I am primarily a C++ programmer.

That is why I was hoping for a set breakpoint in Visual Studio solution.

-- 
Ciao,
Benilda Key
-- 


PhistucK

unread,
Oct 21, 2020, 12:08:45 PM10/21/20
to Ben Key, Chromium Extensions
This group is about using the extension system, less about debugging the browser/renderer. You can ask at blink-dev.
When your breakpoint is hit, what do you see in the stack?

Also, would you like to share a URL to your extension? I can take a look/try and reduce it. You can reply privately with the URL if you want.

PhistucK

Scott Fortmann-Roe

unread,
Oct 21, 2020, 1:31:41 PM10/21/20
to PhistucK, Ben Key, Chromium Extensions
If you do the following in a content script:

  var originalWindowAlert = window.alert;
    window.alert = function() {
      console.trace();
      return originalWindowAlert.apply(window, arguments);
    }

I don't believe it will actually intercept alerts triggered by the page as you are overriding the content script's window.alert method which is different from the page's method (content script JS is isolated from page JS).

To modify the page's alert method you'll probably need to inject a script tag into the page. E.g. something along these lines in the content script:

  let script = document.createElement('script');
  script.textContent = `
   var originalWindowAlert = window.alert;
   window.alert = function() { 
      console.trace()
      return originalWindowAlert.apply(window, arguments);
    } `;
  document.body.appendChild(script);


Ben Key

unread,
Oct 22, 2020, 9:08:47 AM10/22/20
to Chromium Extensions, sco...@gmail.com, Ben Key, Chromium Extensions, PhistucK
Thanks. That is what I needed to know. The console.trace told me exactly what was causing the issue. I wasted a week on the bug already. Now that I know the cause I have been able to fix it after less than a day.
Reply all
Reply to author
Forward
0 new messages