提问人:jack chen 提问时间:11/1/2023 最后编辑:jack chen 更新时间:11/1/2023 访问量:31
当我在Chrome扩展程序中单击右菜单时,如何获取当前的屏幕尺寸?
How To Get The Current Screen Size When I Click Right Menu In Chrome extension?
问:
我有一个 Chrome 扩展程序,当在网页上单击自定义上下文菜单时,我想检索 Service Worker 中的屏幕尺寸。如何在不将脚本注入网页的情况下实现这一点?
我的具体要求是在右键单击菜单时创建一个弹出对话框,并且该对话框需要位于屏幕的中心。因此,我需要获取屏幕的宽度和高度。
我可以像这样在弹出窗口中打开对话框:
const showSelectPopUp = () => {
const width = 420;
const height = 600;
const left = (screen.width / 2) - (width / 2);
const top = (screen.height / 2) - (height / 2);
// open dialog
chrome.windows.create({
url: 'src/selector/selector.html',
type: 'popup',
width: width,
height: height,
left: Math.round(left),
top: Math.round(top),
});
}
如何在service_worker中做到这一点?
答: 暂无答案
评论
window