easonwong-de/Adaptive-Tab-Bar-Colour

PDF Viewer uses color of last visited website

Closed this issue · 6 comments

As the title, says, when I open a PDF in Firefox the header color doesn't change and instead keeps the one from the last website. The console says "No connection to content script." The correct theme should be the same as used in debugging windows.

I would suggest either checking if the title ends on .pdf, or using a default theme whenever an error occurs.

This is going to be fixed in v1.6.4. Besides PDF viewer, tab bar color for image viewer, plain text viewer, load fail error page, and local HTML will also be fixed. v1.6.4 will be out in this week and also includes your contribution.

Falling back to default when an error occurs can cause flickering, because for the first couples of millisecond of page loading, content script isn’t loaded. This is more obvious when the network connection is bad or the website is big.

You can use tabs.executeScript from the background script to load the content script like this:

browser.tabs.executeScript({
    file: "/path/to/script.js"
}).then(changeTheme, setDefaultTheme)

That way you don't even need a connection between the two: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/executeScript#return_value
Maybe you need to specify the tabId to make sure the theme applies on the correct window.

I’ve read the doc and this API is great. But I also want to detect mouse click and page scroll to change tab bar color dynamically, so I think a static content script is maybe still needed.

Yeah right, for this you still need the connection, but you could still load the content script from the background script. However, changing that might be more work than what its worth

Version 1.6.4 is out. Bugs regarding PDF viewer, and alongside with other browser protected pages, should be fixed now. If any abnormality appears again, please let me know.

Unfortunately, it doesn't work since the website doesn't end with .pdf. However, the tab title ends with .pdf, so it should be easy to fix