Skip to content

Commit

Permalink
Catch missing host permission error for restricted pages such as AMO. F…
Browse files Browse the repository at this point in the history
…ix #69.
  • Loading branch information
fwenzel committed Jul 12, 2017
1 parent e119993 commit df8ab72
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"message": "Copy ShortURL for this link",
"description": "Context menu item label text for link."
},

"shorten_error": {
"message": "ZOMG, error creating short URL.",
"description": "Error message when shortening URL was unsuccessful."
Expand All @@ -15,6 +16,10 @@
"message": "No API key in preferences.",
"description": "Error message when shortening service needs an API key and none was provided."
},
"error_host_permission": {
"message": "Sorry, Copy ShortURL cannot run on pages restricted by the browser.",
"description": "Error message when running on about: or addons.mozilla.org."
},

"service_title": {
"message": "URL Shortening Service",
Expand Down
7 changes: 7 additions & 0 deletions src/lib/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import notify from './notify';
import processUrl from './shortener';

const _ = browser.i18n.getMessage;
Expand Down Expand Up @@ -51,6 +52,12 @@ browser.commands.onCommand.addListener((cmd) => {
function discoverUrl() {
browser.tabs.executeScript({
file: '/data/js/find-short-url.js'
}).catch(e => {
if (e.message && /Missing host permission for the tab/.test(e.message)) {
notify(_('error_host_permission'));
} else {
throw e;
}
});
}
browser.runtime.onMessage.addListener(processUrl);
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Detect or create a short URL for the current page.",
"author": "Fred Wenzel",
"homepage_url": "http://copy-shorturl.rtfd.org",
"version": "4.0.1",
"version": "4.0.2",
"default_locale": "en",
"icons": {
"16": "data/img/icon-16.png",
Expand Down

0 comments on commit df8ab72

Please sign in to comment.