Issues with tabs.toggleReaderMode and background tabs

I’m working on porting my add-on ( https://github.com/pmarchwiak/auto-reader-view/tree/webextension ) to the WebExtensions API and running into an issue with the tabs.toggleReaderMode(). I’m listening to the tabs.onUpdated event and once I see that changeInfo.status is “complete”, I am attempting to call browser.tabs.toggleReaderMode(), with changeInfo.tab.id as the argument. This works fine if the onUpdated event is for the currently active tab. However, when a link is opened with “right-click -> Open Link in New Tab”, promise returned by toggleReaderMode() is rejected with the error “Error: The specified tab cannot be placed into reader mode”. I also noticed that the tab.isArticle property remains false if the tab is loaded in the background. When I switch to the new tab I am able to switch to reader mode using the built-in icon. So what seems to be happening is that firefox won’t recognize a tab as an article or allow toggling reader mode until the tab is activated. Is this behavior a bug or expected?

Detecting whether a page can be but into reader mode or not requires quite some work. (The DOM is serialized, passed to a worker, parsed, manipulated and interpreted, serialized back as a JSON result, sent back and parsed again.)

It makes sense that Firefox only does that for the active tab.

It is not documented (yet?), but does onUpdated fire for changes of isArticle? That sounds like it is closer to what you need anyway.

Thanks for the info! I ended up hooking up to onUpdated and checking changeInfo.isArticle. It would be nice if that was a documented API.