0

How can I intercept API calls made by the web application? For example, how can I know the web site uses native file system api and intercept its function when user invokes the above function?

await window.showOpenFilePicker()
knave123
  • 51
  • 4
  • You'll probably need to show more code than that. – Dshiz Jan 19 '21 at 02:55
  • I illustrate my problem in [here](https://stackoverflow.com/questions/65793488/overriding-showopenfilepicker-with-puppeteer) further, can you take a look? – knave123 Jan 19 '21 at 17:27

1 Answers1

0

You can use the facade (aka decorator) pattern to do this.

Inject code into the page using TamperMonkey to do this:

;(() => {
  const old = window.showOpenFilePicker;
  window.showOpenFilePicker = () => {
    console.log('showOpenFilePicker called');
    return old();
  }
})();
Josh Wulf
  • 4,727
  • 2
  • 20
  • 34
  • Unfortunately this not solves my problem. I illustrate my problem in here further, can you take a look? [link](https://stackoverflow.com/questions/65793488/overriding-showopenfilepicker-with-puppeteer) – knave123 Jan 19 '21 at 17:27
  • Override the `window.showOpenFilePicker` using the method shown there. – Josh Wulf Jan 20 '21 at 07:04
  • can you illustrate a simple example? – knave123 Jan 20 '21 at 13:13
  • The example you pointed to shows it. Instead of overriding the `HTMLCanvasElement`, you override the function you want. Like this: `const old = window.showOpenFilePicker; window.showOpenFilePicker = () => {console.log('intercepted'); return old() }` – Josh Wulf Jan 22 '21 at 00:55