Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to fetch remote files dynamically? (no GM_xmlHttpRequest?) #387

Closed
mk-pmb opened this issue Apr 4, 2018 · 4 comments
Closed

How to fetch remote files dynamically? (no GM_xmlHttpRequest?) #387

mk-pmb opened this issue Apr 4, 2018 · 4 comments

Comments

@mk-pmb
Copy link

mk-pmb commented Apr 4, 2018

Update: Solved: A full list of command names can be obtained from the source of the GM4 polyfill. (Hints on @require)


What is the problem?

I can't find (in the docs here or over at Greasespot Wiki) a violentmonkey-compatible way to fetch remote files dynamically.

How to reproduce it?

  1. Visit https://gist.github.com/mk-pmb/3a8faa4cbc7410fbfaccdedfac6360f5
  2. Click the "raw" button to install.
  3. Visit http://spaceweb.pimpmybyte.de/ (or a gist) and observe console.

What is the expected result?

monkey version: Violentmonkey 2.9.0
monkey foo features: {
  "GM": null,
  "GM_info": "object",
  "GM_getResourceUrl": null,
  "GM_xmlHttpRequest": "function",
  "GM_getResourceText": "function",
  "gm_info": null,
  "gm_getResourceUrl": null,
  "gm_xmlHttpRequest": null
}
monkey foo xhr: Object { … }

What is the actual result?

   "GM_getResourceUrl": null,
-  "GM_xmlHttpRequest": "function",
+  "GM_xmlHttpRequest": null,
   "GM_getResourceText": "function",
@@ … @@
 }
-monkey foo xhr: Object { … }
+ReferenceError: GM_xmlHttpRequest is not defined

Environment

  • Browser: Firefox
  • Browser version: 56
  • Violentmonkey version: 2.9.0
  • OS: Ubuntu trusty
@mk-pmb
Copy link
Author

mk-pmb commented Apr 4, 2018

Will the fetch API (window.fetch) be privileged/unrestricted when called from within a UserScript?

@ghost
Copy link

ghost commented Apr 5, 2018

You should be calling GM_xmlhttpRequest (lower-case http) instead of GM_xmlHttpRequest.
Only GM_xmlhttpRequest is privileged.

@mk-pmb
Copy link
Author

mk-pmb commented Apr 5, 2018

Thanks! Where can I look up such details about the VM API? Could have saved me many hours of debugging since I had to guess from the Greasespot Wiki and they only had the new API with uppercase H.

@ghost
Copy link

ghost commented Apr 5, 2018

VM follows the old GM3 API, so, use an old version of the GM wiki page. https://wiki.greasespot.net/index.php?title=Greasemonkey_Manual:API&oldid=7385

The only difference that I know of is that VM additionally supports @exclude-match in the metadata block.

@mk-pmb mk-pmb closed this as completed Apr 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant