How to call function in certain time interval Ask Question

I need to run a certain API function, in a certain time period once the access token is granted, and check the status and inform the user if there any changes.

So far i did it by clicking a button on popup window of the firefox addon and calling the functions background js files, so i can receive the info from the API and notify the user. But i need to automate this process in background js files.

Are there any firefox inbuild JS API or any other way to achieve this auto API request calling from addon background files?

call page function from firefox addon with location.href doesn't work Ask Question

i try to call a javascript function from the original page from my firefox extension content_script like this:

content_scripts.js

location.href="javascript:tellParent('lightboxClose();'); void 0";

This works very well in my Chrome Extension but doesn’t work in my Firefox Addon.

Is there a similar solution or a workaround to call that function from the page?
I’m searching for a solution since hours and can’t get it to work.

Hope you can help me

Firefox extension content script cannot request XMLHttpRequest Ask Question

According to the Firefox Content Script,the XMLHttpRequset can be used.

I have tried both XMLHttpRequest and Api Fectch.It only responses with error message.
I already disable CORS on the server.It still dosen’t work.

I run Django local server on the computer.

This is the code:

function getWord(word){
   var req = new XMLHttpRequest();
   req.open("GET", "http://127.0.0.1:8000/api/${word}/",true);
   req.onload = function(){
      console.log("done");
   }
   req.onerror = function(){
      console.log("error : ",this.error);
   }
   req.send();

Console error:

error { target: XMLHttpRequest, isTrusted: true, lengthComputable: false, loaded: 0, total: 0, currentTarget: XMLHttpRequest, eventPhase: 2, bubbles: false, cancelable: false, defaultPrevented: false, … }

It work on other files(Not extension).

Firefox Extension options page not able to read from Storage Ask Question

In options page I am able to set the data into storage using browser.storage.sync.set({‘data’:’value’}) but when trying to get this data using the below piece of code it does not work in options page but works in pop up page.

var gettingItem = browser.storage.sync.get({‘data’:”});

    gettingItem.then((data) => {
         console.log(data);
       });

Inaccessible array returned by Firefox WebExtensions browser.tabs.query(). Can someone explain why? Ask Question

Can someone explain to me what is going on here? I am playing around with the Firefox WebExtensions API, and I am running into some rather strange behavior. Here is some very simple to code to illustrate the issue.

I am querying for all pinned tabs in all windows and I am expecting that the global array var pinned = []; will be populated with the tab data/objects. However, things are a little screwy to say the least. The array seems to be populated but the individual elements are not accessible using standard array notation pinned[0] returns undefined. I am absolutely perplexed by this.

So what is going on here? Is this an issue about scope or permissions?

Now the code …

[manifest.json]

{
  "manifest_version": 2,
  "name": "test",
  "version": "1.0",
  "description": "test",
  "icons": {
    "48": "icons/page-48_white.png"
  },
  "permissions": [
    "tabs",
    "<all_urls>"
  ],
  "background": {
    "scripts": ["background.js"]
  },
  "devtools_page": "test.html",
  "browser_action": {
    "default_icon": { "48": "icons/page-48_white.png"},
    "default_title": "Test",
    "browser_style": true
  }
}

[background.js]

function createExtPage(){
  browser.tabs.create({ "url": "test.html" });
}
browser.browserAction.onClicked.addListener(createExtPage);

[test.js]

var pinned = [];

browser.tabs.query({pinned: true})
  .then(tabs => {
    for (let [key, value] of tabs.entries() ) {
      console.log("Object " + key, value);
      pinned.push(value);
    }
  });

console.debug("All Pinned Tabs", pinned);
console.debug("First Pinned Tab", pinned[0]);

Now take a look at this output from the Firefox developer tools console.

  All Pinned Tabs
  []
    0: {…}
        active: false
        audible: false
        discarded: false
        favIconUrl: "http://www.crunchyroll.com/favicon.ico?v=1"
        height: 800
        hidden: false
        highlighted: false
        id: 149
        incognito: false
        index: 0
        isArticle: false
        isInReaderMode: false
        lastAccessed: 1522229700160
        mutedInfo: Object { muted: false }
        pinned: true
        sharingState: Object { camera: false, microphone: false }
        status: "complete"
        title: "Crunchyroll - Watch Naruto Shippuden, Bleach, Anime Videos and Episodes Free Online"
        url: "http://www.crunchyroll.com/"
        width: 1440
        windowId: 3
        __proto__: Object { … }
  ​
    1: {…}
        active: false
        audible: false
        discarded: false
        favIconUrl: "https://www.pandora.com/favicon.ico"
        height: 800
        hidden: false
        highlighted: false
        id: 145
        incognito: false
        index: 0
        isArticle: false
        isInReaderMode: false
        lastAccessed: 1522447564848
        mutedInfo: Object { muted: false }
        pinned: true
        sharingState: Object { camera: false, microphone: false }
        status: "complete"
        title: "All Along The Watchtower Radio - Now Playing on Pandora"
        url: "https://www.pandora.com/station/play/3395036678172411653"
        width: 1440
        windowId: 67
        __proto__: Object { … }
  ​
    2: {…}
        active: false
        audible: false
        discarded: false
        height: 800
        hidden: false
        highlighted: false
        id: 171
        incognito: false
        index: 1
        isArticle: false
        isInReaderMode: false
        lastAccessed: 1522398347238
        mutedInfo: Object { muted: false }
        pinned: true
        sharingState: Object { camera: false, microphone: false }
        status: "complete"
        title: "Debugging with Firefox Developer Tools"
        url: "about:debugging"
        width: 1440
        windowId: 67
        __proto__: Object { … }
    length: 3
  ​  __proto__: Array []

  First Pinned Tab undefined

  Object 0
    {…}
      active: false
      audible: false
      discarded: false
      favIconUrl: "http://www.crunchyroll.com/favicon.ico?v=1"
      height: 800
      hidden: false
      highlighted: false
      id: 149
      incognito: false
      index: 0
      isArticle: false
      isInReaderMode: false
      lastAccessed: 1522229700160
      mutedInfo: Object { muted: false }
      pinned: true
      sharingState: Object { camera: false, microphone: false }
      status: "complete"
      title: "Crunchyroll - Watch Naruto Shippuden, Bleach, Anime Videos and Episodes Free Online"
      url: "http://www.crunchyroll.com/"
      width: 1440
      windowId: 3
      __proto__: Object { … }

  Object 1
    {…}
      active: false
      audible: false
      discarded: false
      favIconUrl: "https://www.pandora.com/favicon.ico"
      height: 800
      hidden: false
      highlighted: false
      id: 145
      incognito: false
      index: 0
      isArticle: false
      isInReaderMode: false
      lastAccessed: 1522447564848
      mutedInfo: Object { muted: false }
      pinned: true
      sharingState: Object { camera: false, microphone: false }
      status: "complete"
      title: "All Along The Watchtower Radio - Now Playing on Pandora"
      url: "https://www.pandora.com/station/play/3395036678172411653"
      width: 1440
      windowId: 67
      __proto__: Object { … }

  Object 2
    {…}
      active: false
      audible: false
      discarded: false
      height: 800
      hidden: false
      highlighted: false
      id: 171
      incognito: false
      index: 1
      isArticle: false
      isInReaderMode: false
      lastAccessed: 1522398347238
      mutedInfo: Object { muted: false }
      pinned: true
      sharingState: Object { camera: false, microphone: false }
      status: "complete"
      title: "Debugging with Firefox Developer Tools"
      url: "about:debugging"
      width: 1440
      windowId: 67
      __proto__: Object { … }

Here is the really screwy thing. If I type pinned[0] in the firefox developer tools console I get this result

pinned[0]
  {…}
    active: false
    audible: false
    discarded: false
    favIconUrl: "http://www.crunchyroll.com/favicon.ico?v=1"
    height: 800
    hidden: false
    highlighted: false
    id: 149
    incognito: false
    index: 0
    isArticle: false
    isInReaderMode: false
    lastAccessed: 1522229700160
    mutedInfo: Object { muted: false }
    pinned: true
    sharingState: Object { camera: false, microphone: false }
    status: "complete"
    title: "Crunchyroll - Watch Naruto Shippuden, Bleach, Anime Videos and Episodes Free Online"
    url: "http://www.crunchyroll.com/"
    width: 1440
    windowId: 3
    __proto__: Object { … }    

What gives? Why can I access the array’s elements from the console but not the code?

As you can see the array pinned is populated but I can’t access the individual elements inside using the array. Does anyone know why this is happening?

Manipulating the browser chrome in a web extension Ask Question

I want to develop a small extension to hide the browser chrome for a use case. It seems that the new way to develop addons is to use the web extension api. With the old api it seems to be possible to manipulate the chrome. E.g. in the webdeveloper console (with some config flags) I was able to run this code:

document.getElementById('toolbar-menubar').style.display = 'none';

However it seems to be impossible with the web extension api. Is there any way to do that?

Increase font size on any website Ask Question

I’m trying to create a browser extension that allows users to change the font size on any given page. I’ve already researched increasing font-sizes using JavaScript, and it always says to add stuff like ‘font-size: 2em;’ to the body style. This works, however it doesn’t work for every website.

I’m hoping I can do something similar to the ‘Bigger Text’ button like shown here.

https://userway.org/

(Click on the icon in the top right corner)

Any pointers or suggestions would be greatly appreciated.

Thank you.
Todd

when does Windows Hosts file redirection take place Ask Question

In regards to a browser http request life cycle, before the actual execution of sending the request, at what point does the, so to speak, “DNS” of the windows hosts file take place? After entering a site address into any web browser, when you hit enter, is one of the first things that takes place a check to the hosts file? or perhaps one of the last? Would a javascript chrome extension or firefox add-on be able to override what is in the hosts file at all? Is the point of execution browser dependant?

Opening file Dialog with context menu Ask Question

I am working to create a Web Extension for both google chrome and Firefox.
Ultimately my goal is to open a file dialogue when I click on the context menu item added by my extension. However, there are two major problems when trying to do this.

  1. The file dialogue must be opened by user action that activates an input element with type=file.

  2. Context menu events are added and called from the background script of the extension.

Is there a silver bullet solution I am missing?

Failed Solutions

  1. Background input element: Input elements will not function when used in the background script.
  2. Message Passing (works on Chrome but not Firefox): Sending a message from the background to the content script keeps its user triggered status on chrome, but loses it in Firefox.

For those interested: this is the code that works in Chrome but not Firefox.

Background.js:

chrome.contextMenus.create({
 title: "Clickme",
 contexts:["image"],  // ContextType
 onclick: function(){sendMsg("openDialog")} // Called when clicked in menu
});

Content.js:

var fInput= document.createElement("input"); //hidden input to open filedialog
fInput.setAttribute("type", "file"); //opens files
fInput.setAttribute("id", "fileopeninput"); ////only useful for inspector debugging

///TAKE MESSAGE FROM Background
chrome.runtime.onMessage.addListener(
  function(request, sender, sendResponse) {
    if(request.msg === "openDialog"){
        fInput.click(); //triggers open file dialogue
    }
});

selenium how to select/ refer to the current testing webpage Ask Question

I am using selenium firefox add-on to write test case.

I use the following command to display the webpage that I test.

Then after “http://aaa.com” (test page) is successfully loaded and displayed in my browser.

Say, I know there is a “form” element which has an id of “webform” and it has a unwanted attribute “target” that I want to remove.

In a developer console, I would likely run the following javascript to remove the attribute:
document.findByElementId(‘webform’).removeAttribute(‘target’)

I wonder how to achieve the same thing in selenium add-on?
how do I refer to the page I am testing?
(it seems “document.findByElementId” result in an exception:
[error] Threw an exception: document.findByElementId is not a function)

thanks,