1

I am creating Firefox addons that works like search in chrome. How can i use browser.tabs.create() function with 'url' option?

I have read this article. But In here, there is no documentation of How to use this tab creation with variable url.

//code for CMcontentScript.js-start 

 var tabs = require("../sdk/tabs");

self.on("click", function(node, data) {
     textContent = window.getSelection().toString();
     var searchURL = google.com?searchtid=" + textContent;
     
     tabs.open(searchURL);//In here i want to know how we can add variable url to 'url' option
 });
//code for CMcontentScript.js-ends


//code for index.js-start 

  searchMenu = cm.Item({
                    label: "Search With enadoc",
                    data: setURL,
                    context: cm.SelectionContext(),
                    image: self.data.url("./icon-16.png"),
                 contentScriptFile: "./CMcontentScript.js"
                });
//code for index.js-ends

enter image description here

Sameera Liyanage
  • 1,381
  • 1
  • 12
  • 26

1 Answers1

1

I think you are creating a JPM addon. Which is an SDK addon. This is not a WebExtension. And the chrome.browser.tabs.create is a webextension api.

To create a new tab you should do this:

var tabs = require("sdk/tabs");


self.on("click", function(node, data) {
    var textContent = window.getSelection().toString();
    var searchURL = 'http://www.google.com?searchtid=' + textContent;

    tabs.open(searchURL);
});
Noitidart
  • 35,443
  • 37
  • 154
  • 323
  • this self on click method i added to separate file wich is included "data" folder, so i cant use this "var tabs = require("sdk/tabs");". there is a reference error shows in command promt. – Sameera Liyanage Apr 05 '16 at 05:16
  • @SameeraLiyanage can you put your code to github then share. You should be able to require the file in your data folder and it should work fine. – Noitidart Apr 05 '16 at 06:30