- Apr 25, 2015
- 1,845
- 2
- 2,199
- 327
This is a WIP (Work-In-Progress) as I have never built Google Chrome extensions before, ever.
So keep in mind this is a glorified Hello World app trying to make rocketships launch, might be a lot of smoke!
Anyway, I created the typical manifest file:
Then I have the background.js file:
Finally, the content.js file:
Keep in mind none of this is fully working and the logic is extremely broken at-present, I must fine-tune all of this to have appropriate port/protocol checking so for example if the requested site already has a specified :123 (port) or whatever, there is no sense in checking SRV record as that would over-ride any DNS (I think).
Anyways.. this is full of .log entries, alerts, and stuff and serves as an extremely barebones look at how an extension version of this would function.
At line console.log(parseSrv[2]); --- this is the SRV port resolved.
The next step is to add in error handling in the event SRV records do not exist, add support for checking for both _http and _https then choosing _https if that exists and sending to a redirect via https:// or if _http only exists then send to that via http://
Pretty straight-forward stuff here, just simply a redirect script that works on SRV records, which browsers should already have in-built support for.
Kinda surprised they do not, really
So keep in mind this is a glorified Hello World app trying to make rocketships launch, might be a lot of smoke!
Anyway, I created the typical manifest file:
Code:
{
"name": "SRV HTTPS",
"version": "1.1",
"description": "Adding support for SRV records to web browsing.",
"manifest_version": 2,
"background": {
"scripts":["background.js"]
},
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"js": ["content.js"]
}
],
"permissions": [
"tabs",
"notifications",
"webNavigation",
"background"
]
}
Then I have the background.js file:
Code:
chrome.webRequest.onBeforeRequest.addlistener(function(details)) {
chrome.tabs.executeScript(details.tabId, {"file": "content.js"};
};
Finally, the content.js file:
Code:
var start = async function(a, b) {
var response = await fetch('https://dns.google/resolve?name=_https._tcp.'+window.location.hostname+'&type=srv');
var json = await response.json();
console.log(json);
console.log(json.Answer[0].data);
var srvData = json.Answer[0].data;
var parseSrv = srvData.split(" ");
console.log(parseSrv);//Number 2 is the port
console.log(parseSrv[2]);
alert(window.location.host);
alert(window.location.hostname);
}
start();
Keep in mind none of this is fully working and the logic is extremely broken at-present, I must fine-tune all of this to have appropriate port/protocol checking so for example if the requested site already has a specified :123 (port) or whatever, there is no sense in checking SRV record as that would over-ride any DNS (I think).
Anyways.. this is full of .log entries, alerts, and stuff and serves as an extremely barebones look at how an extension version of this would function.
At line console.log(parseSrv[2]); --- this is the SRV port resolved.
The next step is to add in error handling in the event SRV records do not exist, add support for checking for both _http and _https then choosing _https if that exists and sending to a redirect via https:// or if _http only exists then send to that via http://
Pretty straight-forward stuff here, just simply a redirect script that works on SRV records, which browsers should already have in-built support for.
Kinda surprised they do not, really