首页 > 解决方案 > 使用代理对象覆盖 Chrome 存储 API

问题描述

当使用 JavaScript 代理调用 Chrome 存储 API 时,如何覆盖chrome.storage.local.get以记录存储密钥的值

这是我尝试过的:

const api = chrome.storage.local;
const { set } = api; 
api.set = new Proxy(api.set, {
    apply: (target, thisArg, argumentsList) => {
        console.log(argumentsList[0]);
        return target(argumentsList[0]);
    }
});

被调用Illegal invocation: Function must be called on an object of type StorageArea时出现错误target(argumentsList[0])

标签: javascriptgoogle-chromegoogle-chrome-extensionproxyes6-proxy

解决方案


推荐阅读