firefox扩展:-pagemod不工作

firefox扩展:-pagemod不工作,firefox,firefox-addon,firefox-addon-sdk,Firefox,Firefox Addon,Firefox Addon Sdk,我想在每次加载顶部页面(而不是页面中的iFrame)时修改web页面。据我估计,我需要使用页面修改。但就我而言,它不起作用 1) 创建了包含以下内容的文件“lib/main.js” var pageMod = require("sdk/page-mod"); pageMod.PageMod({ include: "*", contentScriptWhen: 'end', attachTo: ["top", "existing"], contentScript: 'window.alert("

我想在每次加载顶部页面(而不是页面中的iFrame)时修改web页面。据我估计,我需要使用页面修改。但就我而言,它不起作用

1) 创建了包含以下内容的文件“lib/main.js”

var pageMod = require("sdk/page-mod");
pageMod.PageMod({
include: "*",
contentScriptWhen: 'end',
attachTo: ["top",  "existing"],
contentScript: 'window.alert("Page matches ruleset");'
});
<?xml version="1.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>{a2a7da09-1be1-4e24-8324-5560048a3ead}</em:id>
    <em:name>Demo</em:name>
    <em:version>1.0.0</em:version>
    <em:description>Demo for Firefox</em:description>
    <em:type>2</em:type>
    <em:creator>sam</em:creator>
    <em:targetApplication>
      <!-- Firefox -->
      <Description>
        <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
        <em:minVersion>3.0</em:minVersion>
        <em:maxVersion>24.0</em:maxVersion>
      </Description>
    </em:targetApplication>
    <em:targetApplication>      
      <!-- SeaMonkey -->
      <Description>
        <em:id>{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}</em:id>
        <em:minVersion>2.0</em:minVersion>
        <em:maxVersion>2.21</em:maxVersion>
      </Description>      
    </em:targetApplication>
  </Description>
</RDF>
2) 创建了另一个包含以下内容的文件“install.rdf”

var pageMod = require("sdk/page-mod");
pageMod.PageMod({
include: "*",
contentScriptWhen: 'end',
attachTo: ["top",  "existing"],
contentScript: 'window.alert("Page matches ruleset");'
});
<?xml version="1.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>{a2a7da09-1be1-4e24-8324-5560048a3ead}</em:id>
    <em:name>Demo</em:name>
    <em:version>1.0.0</em:version>
    <em:description>Demo for Firefox</em:description>
    <em:type>2</em:type>
    <em:creator>sam</em:creator>
    <em:targetApplication>
      <!-- Firefox -->
      <Description>
        <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
        <em:minVersion>3.0</em:minVersion>
        <em:maxVersion>24.0</em:maxVersion>
      </Description>
    </em:targetApplication>
    <em:targetApplication>      
      <!-- SeaMonkey -->
      <Description>
        <em:id>{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}</em:id>
        <em:minVersion>2.0</em:minVersion>
        <em:maxVersion>2.21</em:maxVersion>
      </Description>      
    </em:targetApplication>
  </Description>
</RDF>

{a2a7da09-1be1-4e24-8324-5560048a3ead}
演示
1.0.0
Firefox演示
2.
山姆
{ec8030f7-c20a-464f-9b0e-13a3a9e97384}
3
24
{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}
2
2.21
有人告诉我我做错了什么。 如果可能,请提供任何基本工作样品

感谢评论中的所有人:

  • OP只需要使用
    cfx
    工具就可以让事情顺利进行

您是否有任何错误或其他信息?如果您使用的是加载项SDK,则不需要创建自己的install.rdf,这是在运行cfx xpi创建xpi文件时为您创建的。如有疑问,请遵循SDK文档中提供的介绍和教程:@canuckistani谢谢。您的评论帮助我的扩展开始工作。现在是最后一期。如何引用具有扩展名的图像?数据文件夹中的任何图像都可以通过相对路径从同一数据文件夹中的scripts/css/html引用。完成此操作。我还想注入Iframe。虽然它正在被注入,并且正在从internet加载URI,但是无法从本地扩展中加载URI。这是一个已知的错误,由于平台安全限制,iframe无法从数据加载。