Better attachemnt method and using ip data

This commit is contained in:
z0ccc 2022-04-13 19:09:56 -04:00
parent 61d52ca16d
commit 1da219b110
2 changed files with 6327 additions and 43 deletions

View file

@ -1,59 +1,68 @@
const attachTab = (tabId) =>{
chrome.debugger.attach({ tabId: tabId }, "1.3", function () {
const attachTab = (tabId, ipData) => {
chrome.debugger.attach({ tabId: tabId }, '1.3', function () {
if (!chrome.runtime.lastError) {
// console.log("attached debugger to tab: " + tabId);
// // https://chromedevtools.github.io/devtools-protocol/tot/ - "geolocation"
// chrome.debugger.sendCommand(
// { tabId: tabId },
// 'Emulation.setLocaleOverride',
// { locale: 'zh-Hans-CN' }
// );
chrome.debugger.sendCommand(
{ tabId: tabId },
"Emulation.setTimezoneOverride",
{ timezoneId: "Asia/Shanghai" }
);
chrome.debugger.sendCommand(
{ tabId: tabId },
"Emulation.setLocaleOverride",
{ locale: "zh-Hans-CN" }
'Emulation.setTimezoneOverride',
{ timezoneId: ipData.timezone }
);
const london = {
latitude: 31.230416,
longitude: 121.473701,
chrome.debugger.sendCommand(
{ tabId: tabId },
'Emulation.setGeolocationOverride',
{
latitude: ipData.lat,
longitude: ipData.lon,
accuracy: 1,
};
chrome.debugger.sendCommand(
{ tabId: tabId },
"Emulation.setGeolocationOverride",
london,
function (result) {
console.log(result);
}
);
// chrome.debugger.sendCommand(
// { tabId: tabId },
// "Emulation.setUserAgentOverride",
// {
// userAgent:
// "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.35",
// },
// { acceptLanguage: "mr-IN" }
// );
// chrome.debugger.sendCommand(
// { tabId: tabId },
// "[Emulation.setLocaleOverride](https://chromedevtools.github.io/devtools-protocol/tot/Emulation/#method-setLocaleOverride)",
// { locale: "mr-IN" }
// );
//chrome.debugger.sendCommand({tabId: tabId}, "Emulation.clearGeolocationOverride");
// chrome.debugger.detach({ tabId: tabId });
chrome.debugger.sendCommand(
{ tabId: tabId },
'Emulation.setUserAgentOverride',
{
userAgent:
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.69',
}
// { acceptLanguage: "en-CA" },
// { platform: "WebTV OS" }
);
}
});
}
};
chrome.tabs.onUpdated.addListener((tabId, change, tab) => {
chrome.debugger.getTargets((results) => {
let result = results.find((obj) => {
return obj.tabId === tabId;
});
if (!result.attached) {
fetch('http://ip-api.com/json/')
.then(response => response.json())
.then(ipData => attachTab(tabId, ipData));
}
});
});
// Detects if there are posts for current url
chrome.tabs.onUpdated.addListener((tabId, change, tab) => {
attachTab(tabId);
});
// chrome.tabs.onCreated.addListener((tab) => {
// console.log(tab.id)
// attachTab(tab.id);
// });
// chrome.tabs.onUpdated.addListener((tabId, change, tab) => {
// console.log(tabId)
// });
// chrome.tabs.onUpdated.addListener((tabId, change, tab) => {
// chrome.debugger.attach({ tabId: tabId }, "1.3", function () {
@ -68,4 +77,14 @@ chrome.tabs.onUpdated.addListener((tabId, change, tab) => {
// );
// }
// });
// });
// });
// chrome.debugger.sendCommand(
// { tabId: tabId },
// "Emulation.setAutomationOverride",
// {
// enabled:
// true,
// },
// );

6265
yarn.lock Normal file

File diff suppressed because it is too large Load diff