提问人:Matt Bryson 提问时间:11/1/2023 最后编辑:Matt Bryson 更新时间:11/2/2023 访问量:23
chrome 扩展 chrome.identity.launchWebAuthFlow - 如何设置弹窗大小?
chrome extension chrome.identity.launchWebAuthFlow - how to set size of popup window?
问:
如何设置弹出窗口大小: https://developer.chrome.com/docs/extensions/reference/identity/#method-launchWebAuthFlowchrome.identity.launchWebAuthFlow
这个问题:在 Chrome launchWebAuthFlow 中设置弹出窗口尺寸? 从 10 年前开始问同样的问题,听起来像是正在开发中,但我看不出 10 年后有什么办法。
现在可能吗?或者您是否必须滚动自己的身份验证流 ui 才能设置大小?
我可以完全控制身份验证页面,但添加大小就像您为其他 chrome ext 弹出窗口所做的那样......
body, html {
width:500px;
height:500px;
}
什么都不做,并且
<script >
window.addEventListener('load', () => {
window.resizeTo(500, 500);
})
</script>
引发大量 CSP 错误
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' http://localhost". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.
即使在清单中作为测试,仍然会在身份验证窗口中抛出错误。unsafe-inline
有什么想法吗?
更新
现在使用这个解决方案和chrome.windows.onCreated
chrome.windows.update
function resizeAuthWindowOnCreated(width:number, height:number) {
chrome.windows.onCreated.addListener(function resizePopup (win) {
if(win && win.id) {
// get current auth win pos, or default to center of screen
const {
top:t = Math.round(window.screen.height/2),
left:l = Math.round(window.screen.width/2),
width:w = 0,
height:h = 0
} = win;
// Resize and re-center the auth window
const opts = {
top: Math.round((t + h/2) - height/2),
left: Math.round((l + w/2) - width/2),
width,
height,
};
chrome.windows.update(win.id, opts);
chrome.windows.onCreated.removeListener(resizePopup);
}
}, {windowTypes:['popup']})
}
然后像...
resizeAuthWindowOnCreated(550, 700);
const response = await chrome.identity.launchWebAuthFlow({
url: authURL,
interactive: true
});
不理想,但现在有效......
答: 暂无答案
评论