Tampermonkey / tampermonkey

Tampermonkey is the most popular userscript manager, with over 10 million users. It's available for Chrome, Microsoft Edge, Safari, Opera Next, and Firefox.
GNU General Public License v3.0
4.3k stars 424 forks source link

Why doesn't GM_xmlhttpRequest() show up in the F12 network panel? #1806

Closed hjyssg closed 1 year ago

hjyssg commented 1 year ago

Hi,

I am debugging my HTTP request performance in Chrome, and I have a few questions as follows:

  1. Why doesn't GM_xmlhttpRequest() show up in the F12 network panel?
  2. On my server, the request is processed under 20ms and the response is fairly small. However, in my script, it takes more than 100ms to finish the HTTP request. Where does this performance gap come from?

Thank you very much.

7nik commented 1 year ago

The request is made in the TM's background "tab": go to the addon's page -> click the gear -> Debug Add-ons -> click Inspect Tampermonkey. Passing data between the page tab and TM's needs some time which adds some latency, so it's better to avoid using GM_XHR if possible.

hjyssg commented 1 year ago

Thank you for the quick answer. According to your experience, what is best practice to do HTTP request in TamperMonkey?

7nik commented 1 year ago

What do you mean? If you can make a direct request - use fetch. If CORS blocks it, use GM_XHR.

hjyssg commented 1 year ago

Thank you very much. I figured out. I thought the browser only allows GM_XHR and prohibits the use of other HTTP libraries.

My Example postData(method, url, data): https://github.com/hjyssg/ShiguReader/blob/dev_frontend_0615/src/TamperMonkeyScript/EhentaiHighighliger_many_request.js