Skip to content

fix: direct WebToEpub link missing host permission - #3149

Open
matthewsong18 wants to merge 1 commit into
dteviot:ExperimentalTabModefrom
matthewsong18:firefox-direct-link
Open

matthewsong18 wants to merge 1 commit into
dteviot:ExperimentalTabModefrom
matthewsong18:firefox-direct-link

Conversation

@matthewsong18

Copy link
Copy Markdown
Contributor

Problem

Opening popup.html directly from the address bar, a bookmark, or the
Firefox homepage ran the same code as clicking the extension icon.
WebToEpub opened a second tab and used the first WebToEpub tab as the
source page.

Firefox lets WebToEpub read its own moz-extension:// URL, so the
existing URL check doesn't stop it and let it attempt injection. Firefox blocks content
scripts on extension pages and returned Missing host permission for the tab.

Fix

  • Use tabs.getCurrent() when the URL has no query string. If WebToEpub
    is already open in a browser tab, initialize the interface there.
  • Only try to load a source page when the URL contains a valid id
    parameter. A direct link without an ID opens the interface without
    importing a page.

Refactor

  • Renamed isRunningInTabMode() to isOpenInBrowserTab() to make it
    clear that the check is about where WebToEpub is open.
  • Renamed configureForTabMode() to importPageFromTabIdInUrl() to
    describe what it does and where it gets the source tab ID.

Testing

  • Reproduced the error in Firefox by opening popup.html directly.
  • To verify in Firefox, open bare popup.html and check that the
    interface loads in one tab without an error.

Refer to #3148

Opening popup.html from a bookmark or homepage ran the toolbar launcher,
which opened a second tab and tried to inject into the first one.
Firefox rejected that injection with a missing host permission error.

Detect when WebToEpub is already open in a browser tab and initialize
the interface there. Only import a source page when the URL supplies a
valid tab ID.
@gamebeaker

Copy link
Copy Markdown
Collaborator

@matthewsong18 can you merge it yourself?

@matthewsong18

Copy link
Copy Markdown
Contributor Author

@matthewsong18 can you merge it yourself?

@gamebeaker Sorry, I'm not sure what you mean? Do you mean merge the PR into the main branch? Or merge updates from main into here? I don't have permission to merge if you mean the first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants