Details
Description
I'd like to inject Javascript into my Anki cards, and I'd like to use ES6 modules for ease of maintenance. However, this doesn't appear to work.
Anki internally uses a QWebEnginePage with setHtml() to build the page. The HTML looks something like this (lots of stuff omitted):
<html class=" webkit chrome linux js"> <head> <title>main webview</title> </head> <body> <div id="qa">a <script type="module"> import {say} from '_moduletesta.mjs'; say("42"); </script> </body> </html>
This is _moduletesta.mjs:
export function say(message) { console.log(message); }
I believe this should print 42 to the console, but it does not. Instead, the inlined script appears to be silently ignored.
Am I doing something wrong here, or is this expected?
I'm using Anki 2.1.13 (built with PyQt 5.12.2 and Qt 5.12.3). Qt 5.12.3 is using Chromium 69.0.3497.128, so ES6 modules should in theory be supported.
(This has also been posted on the Qt forums, Reddit, and the Anki support forums).
Steps to reproduce
- Install Anki from Flathub
- Start Anki with env QTWEBENGINE_REMOTE_DEBUGGING=8080 flatpak run net.ankiweb.Anki
- Import QTBUG-77282.apkg file into Anki, click on deck
QTBUG-77282, click Learn deck - Visit localhost:8080 in Chrome, click main webview
- Check both cards, one with type="module" and one without. The one without type="module" prints 42 to the console, the one with type="module" doesn't.
Attachments
For Gerrit Dashboard: QTBUG-77282 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
279469,2 | Add tst_QWebEnginePage::setHtmlWithModuleImport | 5.14 | qt/qtwebengine | Status: MERGED | +2 | 0 |