Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6023623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:01:58+00:00 2026-05-23T04:01:58+00:00

I’m working on a Firefox extension project that requires me to use the TAB

  • 0

I’m working on a Firefox extension project that requires me to use the TAB key to toggle through all the links on the page, extract the its URL, fetch its source code, and parse it.

Currently, I’m able to use TAB key to toggle through the page to get its URL by the following:

exports.main = function() {};
var pageMod = require("page-mod");

pageMod.PageMod({
  include: "*.org",
  contentScriptWhen: 'ready',
  contentScript:

  'document.onkeydown = function(ev) {var key; ev = ev || event; key = ev.keyCode; if (key == 9) { setTimeout (function(){console.log(document.activeElement.href);'+
  '}, 1000 ); } };'+

  'var a = "Access Tab URL Extraction: New Page Found."; console.log(a);'
});

… and get fetch the source code of any give URL with the following (Wikipedia for example):

exports.main = function() {};

console.log("Start");
var pageWorkers = require("page-worker");

var script = "var elements = document.body.innerHTML; " +

             "  postMessage(elements) " ;

// Create a page worker that loads Wikipedia:
pageWorkers.Page({
  contentURL: "http://en.wikipedia.org/wiki/Internet",
  contentScript: script,
  contentScriptWhen: "ready",
  onMessage: function(message) {
    console.log(message);
  }
});

So, how can I pass in the URL I got from the Pagemod (in this case document.activeElement.href) into Page-worker’s contentURL and make it fetch and display the source code everytime I press the TAB key as new URLs keep being extracted in Pagemod.

I tried the following but it does not work, seems one cannot call page-worker as part of the page-mod’s contentScript?

exports.main = function() {};
var pageMod = require("page-mod");
var pageWorkers = require("page-worker");


pageMod.PageMod({
  include: "*.org",
  contentScriptWhen: 'ready',
  contentScript:

//Get New URLs by Pressing the Tab Key

'document.onkeydown = function(ev) { var key; ev = ev || event; key = ev.keyCode; if (key == 9) { setTimeout (function(){console.log(document.activeElement.href);'+

  '}, 1000 ); } };'+



//Fetch new URL source code

'document.onkeyup = function(ev) { var key; ev = ev || event; key = ev.keyCode; if (key == 9) {'+

'pageWorkers.Page({'+
'contentURL: "document.activeElement.href",'+
'contentScript: "var elements = document.body.innerHTML;"+"postMessage(elements)",'+
'contentScriptWhen: "ready",'+
'onMessage: function(message) {'+
'console.log(message);'+
'}'+
'});'+

   ' } };'

});

Any help will be greatly appreciated! 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:01:59+00:00Added an answer on May 23, 2026 at 4:01 am

    Content scripts can’t use addon-sdk resources, as they run in the context of the webpage. So you have to use message passing. Your keypress handler should pass a message back to the addon with something like

      self.port.emit('url', document.activeElement.href)
    

    and then in your page-mod declaration you’d receive the message and create a page-worker to get the source:

    onAttach: function(worker) {
      worker.port.on('url', function(url) {
        pageWorkers.Page({
          contentURL: url,
          contentScript: script,
          contentScriptWhen: "ready",
          onMessage: function(message) {
            console.log(message);
          }
        });
      });
    }
    

    Note that you’d probably want some validation so you only pass URLs back to the addon, and you’d probably want to deal with errors loading the page in the page-worker.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.