Vadorequest
Vadorequest

Reputation: 17979

Make a simple Firefox extension - Inject content

I developped a few days ago a chrome extension by Inject content. This means that I didn't use any Google chrome browser logic, api or whatever. I create a simple manifest.json that loaded my extension-loader.js which injected scripts into the browser using appendChild into the head html element.

I want to do basically the same thing for a firefox extension, but everything I have found so far seems rather complicated, explaining how to use API and a lot of stuff I don't want nor need to use.

In chrome I used web_accessible_resources to load the scripts I wanted to inject. (libraries and my own logic)

So my question is simple. How to create a simple firefox extension that loads other scripts, present in the extension, into the browser page?

Upvotes: 2

Views: 324

Answers (2)

Sierra C
Sierra C

Reputation: 305

It's quite simple https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/page-mod

var data = require("sdk/self").data;
var pageMod = require("sdk/page-mod");
pageMod.PageMod({
  include: "*.mozilla.org",
  contentScriptFile: data.url("my-script.js")
});

Upvotes: 3

VitaliyG
VitaliyG

Reputation: 1857

There is already Firefox addon Greasemonkey that is designed to load other scripts into browser pages. So you just need to write greasemonkey script that will act as Chrome extension.

Upvotes: 1

Related Questions