Google chrome extension 如何在Chrome Extension中获取内容宽度
我想得到内容的宽度,对其进行一些计算,并赠送一个徽章Google chrome extension 如何在Chrome Extension中获取内容宽度,google-chrome-extension,Google Chrome Extension,我想得到内容的宽度,对其进行一些计算,并赠送一个徽章 let [tab] = await chrome.tabs.query({ active: true, currentWindow: true }); const tabWidth = tab.width; 但是如果我在右边锚定打开devtools,我会得到它作为宽度的一部分。如何获取非devtools大小—窗口的实际大小 chrome.action.onClicked.addListener(async () => { f
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
const tabWidth = tab.width;
但是如果我在右边锚定打开devtools,我会得到它作为宽度的一部分。如何获取非devtools大小—窗口的实际大小
chrome.action.onClicked.addListener(async () => {
function getWidth() {
var msg = {
a: document.body.clientWidth,
b: document.body.scrollWidth,
c: window.innerWidth,
d: window.pageXOffset,
e: document.body.getBoundingClientRect().width,
f: document.body.offsetWidth
};
chrome.runtime.sendMessage(msg);
}
var tab = await chrome.tabs.query({ active: true, currentWindow: true });
chrome.scripting.executeScript({
target: {tabId: tab[0].id},
function: getWidth
}, () => {
console.log('script injected')
})
});
chrome.runtime.onMessage.addListener(msg => {
console.table(msg)
})