I mainly use the technique provided in @dfrankow's answer , but I open 127.0.0.1:0 instead of a fake URL. This approach has two advantages:
- Name resolution error. OK, if I correctly chose the fake URL to avoid opening the existing URL, name resolution will fail. But this is not necessary, so why not just skip this step?
- The server is not listening on TCP port
0 . Using just 127.0.0.1 not enough, because it is possible that the web server is running on the client machine, and I do not want to connect to it by accident. Therefore, I must indicate the port number, but which one? Port 0 is an ideal choice: according to RFC 1700 , this port number is "reserved", that is, servers are not allowed to use this.
An example command line to pass the arguments abc and xyz to your extension:
chrome "http://127.0.0.1:0/?abc=42&xyz=hello"
You can read these arguments in background.js as follows:
chrome.windows.onCreated.addListener(function (window) { chrome.tabs.query({}, function (tabs) { var args = { abc: null, xyz: null }, argName, regExp, match; for (argName in args) { regExp = new RegExp(argName + "=([^\&]+)") match = regExp.exec(tabs[0].url); if (!match) return; args[argName] = match[1]; } console.log(JSON.stringify(args)); }); });
Console output (in the console of the extension base page):
{"abc":"42","xyz":"hello"}
kol
source share