简体   繁体   English

Firefox扩展没有运行内容脚本

[英]Firefox extension not running content script

I'm new to Firefox extension development, and am trying to port the Tab Stacker extension from Chrome. 我是Firefox扩展开发的新手,我正在尝试从Chrome移植Tab Stacker扩展。 So far, I have these files: 到目前为止,我有这些文件:

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

chrome.mainfest: chrome.mainfest:

content tabstacker  content/

install.rdf: install.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>

(email address hidden) (电子邮件地址隐藏)

content/content.js: 内容/ 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);
});

The alert calls are for debugging (I'm not sure which console console.log logs to for an extension). alert调用用于调试(我不确定哪个控制台console.log记录到扩展名)。 But neither are shown, even after restarting the browser. 但即使在重新启动浏览器之后,也都没有显示。 The extension shows up in the add-ons manager. 扩展程序显示在加载项管理器中。 What am I doing wrong? 我究竟做错了什么?

Looks like you're trying to use SDK modules without using the Add-Ons SDK, otherwise that tree would look quite different. 看起来您正在尝试使用SDK模块而不使用Add-Ons SDK,否则该树看起来会完全不同。 Check out the Add-On SDK documentation and the Getting Started section: 查看Add-On SDK文档和“ 入门”部分:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM