Javascript Chrome扩展历史API的代理回调函数

Javascript Chrome扩展历史API的代理回调函数,javascript,google-chrome-extension,proxy,browser-history,es6-proxy,Javascript,Google Chrome Extension,Proxy,Browser History,Es6 Proxy,我想代理chrome.history.search的回调函数以获取历史记录项 以下是一个例子: chrome.history.search({text: '', maxResults: 10}, function(data) { // ... }); 对于这个例子,我想捕获最近访问的10个URL 以下是我尝试过的: chrome.history.search = new Proxy(chrome.history.search, { apply: (target, thisArg

我想代理chrome.history.search的回调函数以获取历史记录项

以下是一个例子:

chrome.history.search({text: '', maxResults: 10}, function(data) {
    // ...
});
对于这个例子,我想捕获最近访问的10个URL

以下是我尝试过的:

chrome.history.search = new Proxy(chrome.history.search, {
    apply: (target, thisArg, argumentsList) => {
      console.log(argumentsList[1])     // this gives me the callback function not the data items
      return target.apply(thisArg, argumentsList)
    }
  })

如何改进此功能以代理chrome.history.API的回调函数并记录传递给回调函数的10个最近访问的URL?

在您自己的自定义回调中执行此操作,然后调用原始回调(如果存在):

chrome.history.search=新代理(chrome.history.search{
应用(目标、目标、参数){
const cb=typeof args[args.length-1]=“function”&&args.pop();
返回target.call(thisObj,…args,res=>{
控制台日志(res);
if(cb)cb(res);
});
},
});