darkreader / darkreader

Dark Reader Chrome and Firefox extension
https://darkreader.org/
MIT License
19.62k stars 2.42k forks source link

[Bug] Extension is broken on Opera Browser #11025

Open merlerm opened 1 year ago

merlerm commented 1 year ago

Prerequisites

Bug Description

Hello, I've been using the extension on Opera for years now without any issues, until it stopped working recently (possibly after an update, but I'm not certain). Opening the extension tab just results in it getting stuck on "Loading, please wait". This is on every website and persists after reinstalling. This is the console error log from chrome://extensions/

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'url')
    at TabManager.getTabURL (index.js:3982:24)
    at TabManager.getActiveTabURL (index.js:4071:25)
    at async Extension.getActiveTabInfo (index.js:5259:28)
    at async Promise.all (index 2)
    at async Extension.collectData (index.js:5219:17)
    at async Object.collect (index.js:5133:28)

I'm on Opera Version:97.0.4719.28

Website Address

Any website

Steps To Reproduce

  1. Install the extension on Opera Version:97.0.4719.28
  2. Attempt to open the extension tab or visit any website

Expected Behavior

Extension activates and darkens websites.

Actual Behavior

Extension gets stuck on "Loading, please wait" and/or doesn't darken websites, keybindings don't work.

Screenshots

No response

Operating System

Manjaro Linux (KDE 5.26.5)

Web Browser name and version

Opera Version:97.0.4719.28

Dark Reader version

4.9.62

Additional Context

No response

bershanskiy commented 1 year ago

Thanks for the stack trace, I know how to add a workaround for this issue. However, I would also like to fix the underlying bug. I was not able to reproduce this bug, so could you please clarify how you reproduce this issue? Perhaps, you could record a video?

bershanskiy commented 1 year ago

Re-opened because I would like to figure the real reason for this bug.

merlerm commented 1 year ago

Hm, I'm not sure how to reproduce since I'm not entirely sure how it happened myself - I suspect the extension stopped working after updates since I haven't changed much myself. I've tested removing every other extension and the issues persist, but I've noticed it's working as intended in incognito mode. Is there any logs or other useful information I could provide?

bershanskiy commented 1 year ago

Is there any logs or other useful information I could provide?

Yes, there is.

In short: if you don't mind, please open browser with a few tabs which you would not consider private and then run a command to query data about them. Specifically:

  1. Please open browser with only tabs you do not consider private. These will work:
  2. Open Dark Reader popup, click with right mouse button on it, in the context menu click "Inspect"
  3. Another window will appear (Developer tools). Go to "Console" tab.
  4. Run the following command: chrome.tabs.query({}, (t) => console.log(JSON.stringify(t, null, 2)))
  5. This will print out information about your tabs
  6. Please look over the list to make sure you don't accidentally forget to close a tab with, e.g., a hotel reservation or a bank login or something
  7. Please post the result here

Long explanation: the underlying issue is in the way we find the currently active tab (which filter we apply). Despite decade of browser API engineering, it is still notoriously buggy task. We already have three different filter fall-backs for various cases, but it appears there is one more case we have to handle.

merlerm commented 1 year ago

Sorry this took a while. I noticed that this might be related to Opera's "workspace" feature (which are basically groups of tabs one can switch between), since in a new browser window the extension seems to work in some workspaces and not in others. I've tried narrowing down a specific tab I had open but with no success. Running the line you posted in the console fails (in any workspace, both in my current browser and a new window), with

VM309:1 Uncaught TypeError: Cannot read properties of undefined (reading 'query')
    at <anonymous>:1:13
(anonymous) @ VM309:1

It would appear chrome.tabs is somehow undefined? It's worth noting that this also fails in a workspace where the extension works