klren0312 / daliy_knowledge

知识积累,正确使用方式是watch
22 stars 4 forks source link

谷歌浏览器插件获取连接的屏幕信息 #807

Open klren0312 opened 5 months ago

klren0312 commented 5 months ago

1. manifest.json中添加权限

{
    "permissions": ["system.display"],
}

2. background.js中添加代码

const getScreenInfo = async () => {
  const list = await chrome.system.display.getInfo()
  return list
}

;(async () => {
  const list = await getScreenInfo()
  console.log(list)
})()
[
    {
        "activeState": "active",
        "availableDisplayZoomFactors": [],
        "bounds": {
            "height": 960,
            "left": 0,
            "top": 0,
            "width": 1440
        },
        "displayZoomFactor": 0,
        "dpiX": 120,
        "dpiY": 120,
        "hasAccelerometerSupport": false,
        "hasTouchSupport": false,
        "id": "2528732444",
        "isEnabled": true,
        "isInternal": true,
        "isPrimary": true,
        "isUnified": false,
        "mirroringDestinationIds": [],
        "mirroringSourceId": "",
        "modes": [],
        "name": "Surface Display",
        "overscan": {
            "bottom": 0,
            "left": 0,
            "right": 0,
            "top": 0
        },
        "rotation": 0,
        "workArea": {
            "height": 930,
            "left": 0,
            "top": 30,
            "width": 1440
        }
    }
]

3. 参考资料

https://developer.chrome.com/docs/extensions/reference/api/system/display?hl=zh-cn