【问题标题】:How to Intercept Native File System API calls made by web application?如何拦截 Web 应用程序进行的本机文件系统 API 调用?
【发布时间】:2021-01-19 02:19:55
【问题描述】:

如何拦截 Web 应用程序发出的 API 调用?例如,如何知道网站使用的是原生文件系统api,并在用户调用上述函数时拦截其函数?

await window.showOpenFilePicker()

【问题讨论】:

  • 你可能需要展示更多的代码。
  • 我在here进一步说明我的问题,你能看一下吗?

标签: javascript google-chrome web puppeteer native-file-system-api-js


【解决方案1】:

您可以使用facade (aka decorator) pattern 来执行此操作。

使用TamperMonkey 将代码注入页面以执行此操作:

;(() => {
  const old = window.showOpenFilePicker;
  window.showOpenFilePicker = () => {
    console.log('showOpenFilePicker called');
    return old();
  }
})();

【讨论】:

  • 不幸的是,这不能解决我的问题。我在这里进一步说明我的问题,你能看一下吗? link
  • 使用那里显示的方法覆盖window.showOpenFilePicker
  • 你能举个简单的例子吗?
  • 您指向的示例显示了它。您无需覆盖HTMLCanvasElement,而是覆盖您想要的功能。像这样:const old = window.showOpenFilePicker; window.showOpenFilePicker = () => {console.log('intercepted'); return old() }
猜你喜欢
  • 2012-09-09
  • 1970-01-01
  • 1970-01-01
  • 2013-06-29
  • 1970-01-01
  • 1970-01-01
  • 2022-07-07
  • 2021-11-20
  • 2011-10-15
相关资源
最近更新 更多