uBlockOrigin / uBlock-issues

This is the community-maintained issue tracker for uBlock Origin
https://github.com/gorhill/uBlock
951 stars 82 forks source link

Extension Doesn't Display Correct Status in Edge (split screen) #2945

Open Andrew-J-Larson opened 1 year ago

Andrew-J-Larson commented 1 year ago

Prerequisites

I tried to reproduce the issue when...

Description

When using the split screen functionality built into Edge, the staus of uBlock Origin only shows for the main page (left side), when switching to the second page in the split (right side), the status of uBlock Origin remains unchanged.

However, I can confirm that still appears to block ads, even when the status is appearing incorrectly.

Note: I'm NOT referring to the apps/custom sites toolbar on the right side of the browser.

A specific URL where the issue occurs.

https://youtu.be/dQw4w9WgXcQ

Steps to Reproduce

  1. Make sure you're in the Edge browser.
  2. Open a page that is normally not blocking ads (you've set this page to not be blocked for example. (this will end up on the left side)
  3. Click on the split screen button and open another page that is set to block ads. (this will end up on the right side)
  4. Click onto the main page (left), notice the status of ublock being grayed out (as it should be).
  5. Click onto the second page (right), notice that the status remains unchanged, even though AD blocking is indeed in effect on the page.

Expected behavior

The status of uBlock Origin should reflect the currently active page when using split screen mode.

Actual behavior

Status of uBlock Origin only shows the status for the main page, ignoring the split screen.

Configuration

```yaml uBlock Origin: 1.52.2 Chromium: 119 filterset (summary): network: 104192 cosmetic: 43397 scriptlet: 18850 html: 0 listset (total-discarded, last-updated): default: user-filters: 0-0, never easylist: 75145-16, 3h.33m easyprivacy: 32851-64, 3h.33m plowe-0: 3720-1073, 3h.33m ublock-badware: 7430-135, 3h.33m ublock-filters: 35166-149, 3h.33m ublock-privacy: 660-6, 3h.32m ublock-quick-fixes: 146-89, 3h.32m ublock-unbreak: 2134-32, 3h.33m urlhaus-1: 10900-0, 3h.32m filterset (user): [empty] trustedset: added: [array of 16 redacted] userSettings: [none] hiddenSettings: [none] supportStats: allReadyAfter: 493 ms (selfie) maxAssetCacheWait: 134 ms ```
gorhill commented 1 year ago

chrome.tabs.query({ active: true, currentWindow: true }) keeps returning example.com loaded in the left side. I did try to use { active: true, lastFocusedWindow: true }, no difference. There doesn't seem a way to get the right side of a tab in split-screen mode.

Andrew-J-Larson commented 9 months ago

chrome.tabs.query({ active: true, currentWindow: true }) keeps returning example.com loaded in the left side. I did try to use { active: true, lastFocusedWindow: true }, no difference. There doesn't seem a way to get the right side of a tab in split-screen mode.

Yeah, looks like Microsoft didn't think it through when releasing the feature: https://github.com/microsoft/MicrosoftEdge-Extensions/discussions/102

Andrew-J-Larson commented 9 months ago

I think I figured out a work around.

Using the active tab and window, you should check the results of document.hasFocus().

If true, then you're using the main window (or left split tab), but if false, you'll want to check each "inactive" tabs in the current window where document.hasFocus() ends up as true, being the second tab (main window's right split tab).

Then, you should be able to find the split tab, right?

Andrew-J-Larson commented 9 months ago

I did test part of my theory with document.hasFocus() by checking the values on an interval, and that properly works when using the split tab, but I'm not an extensions dev to try testing the chrome extension API...

Andrew-J-Larson commented 9 months ago

I think I figured out a work around.

Using the active tab and window, you should check the results of document.hasFocus().

If true, then you're using the main window (or left split tab), but if false, you'll want to check each "inactive" tabs in the current window where document.hasFocus() ends up as true, being the second tab (main window's right split tab).

Then, you should be able to find the split tab, right?

And if this works, the proposed implementation shouldn't cause any issues once Edge does fix detection of the split tab (since querying the active tab and checking document.hasFocus() would both come back true).

gorhill commented 9 months ago

document.hasFocus() is not something visible to the main uBO process.

With a breakpoint at https://github.com/gorhill/uBlock/blob/1.55.0/platform/common/vapi-background.js#L650, the focused pane is always the one on the left even after I click on the right pane.

Andrew-J-Larson commented 9 months ago

document.hasFocus() is not something visible to the main uBO process.

With a breakpoint at https://github.com/gorhill/uBlock/blob/1.55.0/platform/common/vapi-background.js#L650, the focused pane is always the one on the left even after I click on the right pane.

I see what you mean, but is something more like this possible, where you check all inactive (active: false) tabs, and then run code on each to confirm which has focus (probably as a separate check after the active tabs check)?

 vAPI.tabs.query({ active: false, windowId }).then(tabs => {
    if ( tabs.length === 0 ) { return; }
    const tab = tabs[0];
    chrome.tabs.executeScript(tab.id, {
      code: 'document.hasFocus()'
    }, function(hasFocus) {
      if (hasFocus) {
        this.onActivated({ tabId: tab.id, windowId: tab.windowId });
      }
    });
});
zaunere commented 1 month ago

Any news on this? I'd like to split the browser programmatically from an extension, the same as the little split window icon in the menu area.

Thanks,

Hans