Skip to content

Commit

Permalink
Merge branch 'ffox-pdf'
Browse files Browse the repository at this point in the history
  • Loading branch information
diegodlh committed Jun 9, 2020
2 parents 4d7125d + 141fa0d commit ba5d3ba
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions src/background/sidebar-injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,15 @@ export default function SidebarInjector(chromeTabs, dependencies) {
}
}, function(error) {
if (error.message === 'Missing host permission for the tab') {
// Assume that any file or http URLs that trigger this error
// (ie. not a protected scheme) are PDFs. See issue #260.
return CONTENT_TYPE_PDF;
if (!isFirefoxRestrictedDomain(tab.url)) {
// Assume that any file or http URLs that trigger this error
// (ie. not a protected scheme) are PDFs. See issue #260.
return CONTENT_TYPE_PDF;
} else {
throw error;
}
} else {
return guessContentTypeFromURL(tab.url);
throw error;
}
});
} else {
Expand Down Expand Up @@ -212,6 +216,32 @@ export default function SidebarInjector(chromeTabs, dependencies) {
});
}

function isFirefoxRestrictedDomain(url) {
// Injection of content scripts in Firefox is blocked in some domains,
// see https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts
var parsedURL = new URL(url);
var RESTRICTED_DOMAINS = [
'accounts-static.cdn.mozilla.net',
'accounts.firefox.com',
'addons.cdn.mozilla.net',
'addons.mozilla.org',
'api.accounts.firefox.com',
'content.cdn.mozilla.net',
'content.cdn.mozilla.net',
'discovery.addons.mozilla.org',
'input.mozilla.org',
'install.mozilla.org',
'oauth.accounts.firefox.com',
'profile.accounts.firefox.com',
'support.mozilla.org',
'sync.services.mozilla.com',
'testpilot.firefox.com'
]
return RESTRICTED_DOMAINS.some(function (hostname) {
return parsedURL.hostname === hostname;
});
}

function injectIntoLocalDocument(tab) {
return detectTabContentType(tab).then(function (type) {
if (type === CONTENT_TYPE_PDF) {
Expand Down

0 comments on commit ba5d3ba

Please sign in to comment.