Skip to content

Instantly share code, notes, and snippets.

@kentbrew
Last active June 21, 2017 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kentbrew/190a0ad83f037567eb2393c235e78043 to your computer and use it in GitHub Desktop.
Save kentbrew/190a0ad83f037567eb2393c235e78043 to your computer and use it in GitHub Desktop.
Firefox Won't Open a New Tab from an Iframe in a Web Extensions Browser Extension

Firefox Won't Open a New Tab from an Iframe in a Web Extensions Browser Extension

Installation

Save manifest.json, content.js, and iframe.html into a new directory.

In Chrome

In chrome://extensions, enable Developer Mode, drag your new directory in until you see Drop to Install, and then drop.

In Firefox

In about:preferences, be sure Open New Windows in a New Tab Instead is checked.

In a console window, use web-ext thusly:

web-ext run --firefox-profile=default

Observed in Chrome:

  • Iframe renders, top right, with a link.
  • Click the link.
  • URL specified in link (currently Mozilla, but could be anything) opens in new tab or window.

Observed in Firefox:

  • Iframe renders, top right, with a link.
  • Click the link.
  • A blank page opens in new tab.
  • No error messages or other feedback appear anywhere.
  • In about:preferences, uncheck Open New Windows in a New Tab Instead and try again.
  • The correct page appears in a new window
var browser = chrome || browser;
var iframe = document.createElement('IFRAME');
iframe.style.position = 'fixed';
iframe.style.height = '100px';
iframe.style.width = '300px';
iframe.style.top = '0';
iframe.style.right = '0';
iframe.src = browser.extension.getURL('iframe.html');
document.body.appendChild(iframe);
<!doctype html>
<html>
<head>
<title>Iframe Test</title>
<meta charset="utf-8">
<style>
body {
background: #fff;
}
</style>
</head>
<body>
<a href="https://www.mozilla.org/" target="_blank">Open New Page</a>
</body>
</html>
{
"version": "1.0.0",
"name": "Open Page from Iframe",
"description": "Why can't I open a new tab from an iframe in Firefox?",
"permissions": [
"*://*/*"
],
"content_scripts": [
{
"js": [ "content.js"],
"matches": [ "*://*/*" ]
}
],
"web_accessible_resources": [
"iframe.html"
],
"manifest_version": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment