javascript - Firefox 扩展未运行内容脚本

标签 javascript firefox firefox-addon

我是 Firefox 扩展开发的新手,正在尝试移植 Tab Stacker来自 Chrome 的扩展。到目前为止,我有这些文件:

$ tree
.
├── chrome.manifest
├── content
│   └── content.js
└── install.rdf

chrome.mainfest:

content tabstacker  content/

安装.rdf:

<?xml version="1.0" encoding="utf-8"?><!-- This Source Code Form is subject to the terms of the Mozilla Public
   - License, v. 2.0. If a copy of the MPL was not distributed with this
   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">
  <Description about="urn:mozilla:install-manifest">
    <em:id>me@gmail.com</em:id>
    <em:version>0.1</em:version>
    <em:type>2</em:type>
    <em:bootstrap>true</em:bootstrap>
    <em:unpack>false</em:unpack>

    <!-- Firefox -->
    <em:targetApplication>
      <Description>
        <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
        <em:minVersion>29.0</em:minVersion>
        <em:maxVersion>29.*</em:maxVersion>
      </Description>
    </em:targetApplication>

    <!-- Front End MetaData -->
    <em:name>Tab Stacker</em:name>
    <em:description>Moves selected unpinned tabs to the left of the tab bar. Port of the Chrome extension of the same name.</em:description>
    <em:creator>James Wood</em:creator>

    <em:optionsType>2</em:optionsType>

  </Description>
</RDF>

(电子邮件地址隐藏)

内容/content.js:

var tabs = require('sdk/tabs');
var timeout = -1;
alert('loaded');

tabs.on('activate', function () {
    window.clearTimeout(timeout);
    alert('activate');
    if (!tabs.activeTab.isPinned)
        timeout = window.setTimeout(function () {
            tabs.activeTab.index = tabs.map(function (t) {
                return t.isPinned;
            }).reduce(function (acc, x) {
                return x ? acc + 1 : acc;
            }, 0);
        }, 1000);
});

alert 调用用于调试(我不确定哪个控制台console.log 会记录扩展)。但即使重新启动浏览器后,也不会显示。该扩展显示在附加组件管理器中。我做错了什么?

最佳答案

看起来您正在尝试使用 SDK 模块而不使用附加 SDK,否则该树看起来会完全不同。查看附加 SDK 文档和入门部分:

https://developer.mozilla.org/en-US/Add-ons/SDK

关于javascript - Firefox 扩展未运行内容脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23550530/

相关文章:

javascript - 将拖动运动限制在圆形 SVG 边界内

javascript - 在 Firefox 上,CORS 请求给出错误 ":"(冒号)

javascript - JS提示错误: for-loop local variable is already defined

java - selenium 无法获取 URL?

firefox-addon - Firefox 插件中的 Ajax

javascript - 包含 4 位数字和 2 个可选字母的邮政编码的正则表达式

java - Selenium 3 中的 profile.setEnableNativeEvents(false)

html - 在 Internet Explorer 和 Mozilla Firefox 中通过 CSS 更改图像对比度

javascript - 如何在 Firefox 扩展程序的新选项卡中打开 URL?

javascript - 从 Firefox 扩展执行 JS