9

One way of running Javascript on a website is to use for instance Greasemonkey. By any chance, would it be possible to execute Javascript commands from Mathematica?

anderstood
  • 14,301
  • 2
  • 29
  • 80

2 Answers2

9

This is now possible in Mathematica 12.

For example , you can open a new tab in web browser using following code:

session = StartWebSession[]

WebExecute["OpenPage" -> "https://www.wolfram.com"]

WebExecute["JavascriptExecute" -> "window.open('https://www.wolframalpha.com', '_blank')"]

For additional information , visit : https://reference.wolfram.com/language/ref/WebExecute.html

Hossein Hadi
  • 635
  • 5
  • 11
2

It might be relevant, you can run both in the browser https://github.com/JerryI/wljs-interpreter

Kirill Vasin
  • 1,235
  • 12
  • 14
  • WLJS does not work for me under macOS 14.0 -- neither the Electron cross-platform app nor the console/web-browser combination. I do have WolframEngine installed and activated with Wolfram; I also have wolframscript and Mathematica. With fomer after all the downloading aftrer i open the app, I get a totally blank window in which I see nothing and can type nothing; with the console/browser combination, after wolframscript -f Scripts/run.wlsI see af binary write error and then the indicated browser URL cannot be opened. – murray Oct 20 '23 at 20:57
  • Hi, @murray. Please consider this guide https://jerryi.github.io/wljs-docs/docs/frontend/Troubleshooting. May be a prebuilt binary of some internal libraries is missing for your WL + OS combo, but this is usually an easy fix :) – Kirill Vasin Oct 20 '23 at 22:31