Create new function in contentScriptFile in Firefox extension

Create new function in contentScriptFile in Firefox extension

By : Mike Lafky
Date : November 24 2020, 05:47 AM
like below fixes the issue I think the content script is being sandboxed from the HTML, so when the anchor is injected into the HTML, it doesn't know what myFun is. Within your content script, you can just bind the handler there, keeping it within the same environment.
code :

Share : facebook icon twitter icon
My Firefox extension is not working. What's the structure of a Firefox extension (XPI file) that uses C++ XPCOM componen

My Firefox extension is not working. What's the structure of a Firefox extension (XPI file) that uses C++ XPCOM componen

By : Ádám Gólya
Date : March 29 2020, 07:55 AM
it should still fix some issue I guess that you are following an outdated tutorial, most tutorials haven't been updated to XPCOM changes in Gecko 2.0. But to your questions:
code :
interfaces components/mycomponent.xpt
binary-component components/mycomponent.dll ABI=WINNT_x86-msvc
form.submit is not a function - How to create and POST a form with (pure) Javascript in a Firefox extension

form.submit is not a function - How to create and POST a form with (pure) Javascript in a Firefox extension

By : Quy Nguyen
Date : March 29 2020, 07:55 AM
help you fix your problem When you create a new element "form", you are creating it in the scope of the browser, hence you are creating a xul element. You would have to do it the way you create the "body" element:
code :
var form = document.createElementNS('http://www.w3.org/1999/xhtml', 'form');
Firefox add-on pageMod, catch ajax done in contentScriptFile

Firefox add-on pageMod, catch ajax done in contentScriptFile

By : CK Yap
Date : March 29 2020, 07:55 AM
like below fixes the issue Put this not in a content script: Im not sure how you will identify the content window of the script. I dont know sdk so well. But see the area CONTENT_WINDOW_OF_CONTENT_SCRIPT
code :
const { Ci, Cu, Cc, Cr } = require('chrome'); //const {interfaces: Ci, utils: Cu, classes: Cc, results: Cr } = Components;

var observers = {
    'http-on-modify-request': {
        observe: function (aSubject, aTopic, aData) {
            console.info('http-on-modify-request: aSubject = ' + aSubject + ' | aTopic = ' + aTopic + ' | aData = ' + aData);
            var httpChannel = aSubject.QueryInterface(Ci.nsIHttpChannel);
            var requestUrl = httpChannel.URI.spec
            var goodies = loadContextAndGoodies(aSubject, true);
            if (goodies.contentWindow) {
               if (goodies.contentWindow == CONTENT_WINDOW_OF_CONTENT_SCRIPT) {
                    //do something here
        reg: function () {
            Services.obs.addObserver(observers['http-on-modify-request'], 'http-on-modify-request', false);
        unreg: function () {
            Services.obs.removeObserver(observers['http-on-modify-request'], 'http-on-modify-request');
function loadContextAndGoodies(request, return_goodies) {
  var loadContext = null;

  if (request instanceof Ci.nsIRequest) {
      try {
          if (request.loadGroup && request.loadGroup.notificationCallbacks) {
              loadContext = request.loadGroup.notificationCallbacks.getInterface(Ci.nsILoadContext);
      } catch (ex) {
        console.exception('request loadGroup with notificationCallbacks but oculd not get nsIloadContext', ex);
      if (!loadContext) {
        try {
            if (request.notificationCallbacks) {
                loadContext = request.notificationCallbacks.getInterface(Ci.nsILoadContext);
        } catch (ex) {
          console.exception('request has notificationCallbacks but could not get nsILoadContext', ex);
          /* start - noit's backup try, it might be redundant (im not sure) as Wladamir Palant didn't have this way*/
          try {
            var interfaceRequestor = httpChannel.notificationCallbacks.QueryInterface(Ci.nsIInterfaceRequestor);
            loadContext = interfaceRequestor.getInterface(Ci.nsILoadContext);
          } catch (ex) {
            console.exception('backup method failed:' ex);
          /* end - my backup try, it might be redundant as Wladamir Palant didn't have this way*/
  } else {
    console.warn('request argument is not instance of nsIRequest')

  if (return_goodies) {
    if (!loadContext) {
      return null;

    var contentWindow = loadContext.associatedWindow;
    var DOMWindow = contentWindow.top.QueryInterface(Ci.nsIInterfaceRequestor)
    var gBrowser = DOMWindow.gBrowser;
    if (gBrowser) {
      var tab = gBrowser._getTabForContentWindow(contentWindow.top);
      var browser = tab.linkedBrowser;
    } else {
      var tab, browser = null;
    var goodies = {
      loadContext: loadContext,
      DOMWindow: DOMWindow,
      gBrowser: gBrowser,
      contentWindow: contentWindow,
      browser: browser,
      tab: tab

    return goodies;
  } else {
    return loadContext;
for (var o in observers) {
for (var o in observers) {
How to use a contentScriptFile from an external URI in a Firefox addon

How to use a contentScriptFile from an external URI in a Firefox addon

By : pgetsos
Date : March 29 2020, 07:55 AM
may help you . My latest update to a Firefox addon has been rejected because I've used a custom jquery-ui (generated by their site with just the widgets I wanted) and it fails their checksum check. ,
Firefox add-on : passing value from context menu to contentScriptFile after selection

Firefox add-on : passing value from context menu to contentScriptFile after selection

By : ยายโบว์วี่ ติดแรด
Date : March 29 2020, 07:55 AM
I wish this helpful for you The function in your data.js is called parseElement. But a selection can contain part of an element, or many elements, each of which can have its own HTML tag and CSS properties. It's actually quite complicated.
In a content script, document.getSelection() will return a Selection object. This Selection contains a number of Ranges given by document.getSelection().rangeCount. The first range (there won't be more than one unless you have selected multiple ranges using the ctrl-key) is given by document.getSelection().getRangeAt(0). For the rest of this answer I'll assume only one range in the Selection, which should cover the vast majority of use cases. The following expression represents the single-range selection:
code :
var selection = document.getSelection();
var range = selection.getRangeAt(0);
var ancestorContainer = range.commonAncestorContainer;
var nodeIterator = document.createNodeIterator(
  // first argument is the root node at which to begin the NodeIterator's traversal:
 // second argument 'whatToShow'; we're interested in elements:
 // third argument 'filter', a function whose return value tells iterator which nodes to iterate over.
 function (node) {
  return selection.containsNode(node) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT;
var elementsWithinSelection = [];
var e = nodeIterator.nextNode();
while (e) {
 e = nodeIterator.nextNode();
self.postMessage(JSON.stringify(elementsWithinSelection.map(function (e) {
 return e.outerHTML;
Related Posts Related Posts :
  • angular 6 Please add a @NgModule annotation
  • Trying to cast element ID to class selector in jQuery
  • Swipe JS - Display 3 Slides at a time
  • Jasmine test to call function when value is null
  • Redux reducer gets string instead of object
  • Keep chrome javascript running even if page reload
  • The event.target.value is not insert the userinput into a variable
  • Exporting HTML tables to Excel (.xls) in a separate sheet
  • Jquery tooltip on dialog close button
  • access variable inside anonymous function from outside
  • How come func is called from a function?
  • How to change add and remove active class in JavaScript
  • how to toggle a specific div in javascript
  • How to get all the values from multiple keys of an array of object?
  • jQuery bind() unbind() and on() and off()
  • regular expression to find DD Month YYYY from a string
  • How to upload files from web client (HTML/jQuery form) to your Dropbox folder
  • Backbone history and require.js issue
  • Confusion over Classical and Prototypal Inheritance Javascript
  • How to take screen shot of current webpage using Javascript/JQuery?
  • Store meridiem in a variable
  • class declared inside closure vs standard class without closure
  • javascript confirm box always return true
  • dynamically changing the size of font size based on text length using css and html
  • Node.js - Getting the host IP address while on Amazon EC2
  • Confusing CSS, can anyone explain please
  • How to install v8-profiler on Windows 8 (64 bit) using npm?
  • Resolve promise based on another promise
  • google maps adding overlay layer above UI and markers
  • Style specific letter?
  • RangeError: Maximum call stack size exceeded with array.slice
  • node rest client get with local variable
  • If condition not executes while mouse move fastly
  • Count the number of displayed elements in a HTML list
  • Locate JavaScript source code in Emacs
  • Clean, Modular Code vs MV* Frameworks
  • infinite scroll without loading image
  • Backbone: reverse collection order with comparator
  • What do printers ignore?
  • jQuery UI .tabs() Contentless tab?
  • Execute Javascript alert() after page (visually) loaded
  • JavaScript - duplicating array doesn't work
  • Excessive clickable area below image
  • JavaScript Regex: Replace |b| with <b>
  • Unexpected value change in 2D array in JavaScript
  • Function doesnt see parameter as a array of objects
  • jQuery fetch keypress event on chrome and IE
  • How to enable jquery validate localization?
  • Cassandra map collection returned by node.js Helenus looks odd
  • angular ng-repeat with multiple filter options
  • Selecting Children without ID or Class names
  • How to uncheck a group of checkboxes when another checkbox is checked
  • Is hiding content by Javascript or jQuery Worth trying
  • Load XUL resource using javascript
  • XML to HTML text area from server file system
  • set focus() on textbox on form onload
  • es lint '' is assigned a value but never used' eventhough i have used it
  • Can "name" attribute be used for custom VueJS components
  • Get innerHTML of content when it is clicked
  • HTTPS causes CSS animations to not load? Very confused
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org