hypothesis / hypothesis/browser-extension
Extension fails to activate on PDFs in current Firefox versions
- Dominant language
- JavaScript
- Stars
- 553
- Forks
- 141
- PR merge metrics
- No merged PRs in 30d
Description
Attempting to activate the Firefox extension on a PDF fails, with an exclamation icon being displayed on the badge. Clicking the badge a second time for more details results in an error "Missing host permissions for tab".
**Steps to reproduce:**
1. Build Firefox extension and load it in Firefox
2. Open a PDF in a new tab and try to activate the extension
**Notes:**
Using the debugger shows that the error is happening when trying to determine the content type. Specifically the [`executeScriptFn` call here](https://github.com/hypothesis/browser-extension/blob/d951a948ae2f6d5056e7cbd01ac473bfb817a3b0/src/background/sidebar-injector.js#L164) fails with a rejected promise. Some Googling found [this forum thread](https://discourse.mozilla.org/t/extensions-on-pdfjs-pages/28441/4) which indicates that this is not a bug but a restriction on activating Firefox extensions on protected pages, including the built-in PDF viewer.
I think what we'll need to do instead is implement some fallback method of detecting the content type and then replacing the tab, much like we do in Chrome.
The simplest fallback we can implement is to use the URL, although not all PDF URLs contain paths that end with `.pdf`. If we can't get access to the actual content type, one option might be to simply assume that any `file` or `http` URLs that trigger this error (ie. not a protected scheme) are PDFs. I expect there will be a small number of HTTP URLs (Mozilla-specific ones) which are restricted, as is the case in Chrome, but it is much more likely that the content is a PDF.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.