Better attachemnt method and using ip data
This commit is contained in:
parent
6442e8fc31
commit
278d0d0522
2 changed files with 6327 additions and 43 deletions
|
|
@ -1,59 +1,68 @@
|
||||||
const attachTab = (tabId) =>{
|
const attachTab = (tabId, ipData) => {
|
||||||
chrome.debugger.attach({ tabId: tabId }, "1.3", function () {
|
chrome.debugger.attach({ tabId: tabId }, '1.3', function () {
|
||||||
if (!chrome.runtime.lastError) {
|
if (!chrome.runtime.lastError) {
|
||||||
// console.log("attached debugger to tab: " + tabId);
|
// chrome.debugger.sendCommand(
|
||||||
// // https://chromedevtools.github.io/devtools-protocol/tot/ - "geolocation"
|
// { tabId: tabId },
|
||||||
|
// 'Emulation.setLocaleOverride',
|
||||||
|
// { locale: 'zh-Hans-CN' }
|
||||||
|
// );
|
||||||
|
|
||||||
chrome.debugger.sendCommand(
|
chrome.debugger.sendCommand(
|
||||||
{ tabId: tabId },
|
{ tabId: tabId },
|
||||||
"Emulation.setTimezoneOverride",
|
'Emulation.setTimezoneOverride',
|
||||||
{ timezoneId: "Asia/Shanghai" }
|
{ timezoneId: ipData.timezone }
|
||||||
);
|
);
|
||||||
|
|
||||||
chrome.debugger.sendCommand(
|
chrome.debugger.sendCommand(
|
||||||
{ tabId: tabId },
|
{ tabId: tabId },
|
||||||
"Emulation.setLocaleOverride",
|
'Emulation.setGeolocationOverride',
|
||||||
{ locale: "zh-Hans-CN" }
|
{
|
||||||
);
|
latitude: ipData.lat,
|
||||||
|
longitude: ipData.lon,
|
||||||
const london = {
|
|
||||||
latitude: 31.230416,
|
|
||||||
longitude: 121.473701,
|
|
||||||
accuracy: 1,
|
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(
|
chrome.debugger.sendCommand(
|
||||||
// { tabId: tabId },
|
{ tabId: tabId },
|
||||||
// "[Emulation.setLocaleOverride](https://chromedevtools.github.io/devtools-protocol/tot/Emulation/#method-setLocaleOverride)",
|
'Emulation.setUserAgentOverride',
|
||||||
// { locale: "mr-IN" }
|
{
|
||||||
// );
|
userAgent:
|
||||||
//chrome.debugger.sendCommand({tabId: tabId}, "Emulation.clearGeolocationOverride");
|
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.69',
|
||||||
// chrome.debugger.detach({ tabId: tabId });
|
}
|
||||||
|
// { 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
|
// Detects if there are posts for current url
|
||||||
chrome.tabs.onUpdated.addListener((tabId, change, tab) => {
|
// chrome.tabs.onCreated.addListener((tab) => {
|
||||||
attachTab(tabId);
|
// 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.tabs.onUpdated.addListener((tabId, change, tab) => {
|
||||||
// chrome.debugger.attach({ tabId: tabId }, "1.3", function () {
|
// chrome.debugger.attach({ tabId: tabId }, "1.3", function () {
|
||||||
|
|
@ -69,3 +78,13 @@ chrome.tabs.onUpdated.addListener((tabId, change, tab) => {
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
// });
|
// });
|
||||||
|
|
||||||
|
|
||||||
|
// chrome.debugger.sendCommand(
|
||||||
|
// { tabId: tabId },
|
||||||
|
// "Emulation.setAutomationOverride",
|
||||||
|
// {
|
||||||
|
// enabled:
|
||||||
|
// true,
|
||||||
|
// },
|
||||||
|
// );
|
||||||
Loading…
Add table
Reference in a new issue