0

我正在创建一个 chrome 扩展,它可以在点击扩展上获取显示信息 [ screen-dimension ]。我使用以下 API 取得了成功

chrome.system.display.getInfo();

此 API 提供所有附加显示的信息 [这真的很棒],但我真正想要的是,我想获取我的 chrome 浏览器打开的那个屏幕的显示信息。

例如 我有屏幕,屏幕一:1980 * 1280,屏幕二:1680 * 980,

现在,如果我的 chrome 浏览器窗口在屏幕二上打开,那么我想要的信息是 1680 * 980,如果我的 chrome 浏览器窗口在屏幕一上打开,那么我想要的信息是 1980 * 1280。

使用文档 https://developer.chrome.com/docs/extensions/reference/system_display/

我已经阅读了文档,也许我遗漏了一些东西。所以请帮助我确定我在这里缺少什么或我可以改进自己的地方

谢谢

4

1 回答 1

0

我还没有找到任何使用 chrome 扩展 API 的准确解决方案。

但是,我使用的方法是,

我创建了一个内容脚本,它读取活动屏幕的窗口对象,并通过向我的 chrome 扩展程序发送消息来为我提供该屏幕的尺寸。

// ContentScript.ts

chrome.runtime.onMessage.addListener((request, _sender, response) => {
        const {
            screen: { height, width },
            innerHeight,
            innerWidth,
            devicePixelRatio,
        } = window;

        const displayInfo = {
            height: height * devicePixelRatio,
            width: width * devicePixelRatio,
            tabHeight: innerHeight,
            tabWidth: innerWidth,
        };

        if (request.requestType === 'getDisplayInfo' && displayInfo) {
            response(displayInfo);
        }
    });

谢谢

于 2021-08-26T12:07:13.797 回答