Closed agneshraok closed 10 months ago
Does the JavaScript in the page get executed? Does this version of QtWebEngine support web components/custom elements? Are there any messages being output to the console (see https://doc.qt.io/qt-6/qtwebengine-debugging.html)?
Does the JavaScript in the page get executed?
Yes it does get executed.
Does this version of QtWebEngine support web components/custom elements?
I am guessing this is the reason why it is not being rendered, Although I didn't find any details about this in QT documentation and I do not know how to confirm this otherwise.
Are there any messages being output to the console (see https://doc.qt.io/qt-6/qtwebengine-debugging.html)?
No.
You can check for custom elements support by executing the following JavaScript code: "registerElement" in document
. If this returns false
, custom elements are not supported.
Thanks for your input, I found out that registerElement
is deprecated and I used the following code to confirm custom element support.
class CustomElement extends HTMLElement {
constructor() {
super();
this.textContent = "Hello, I am a custom element!";
}
}
customElements.define("custom-element", CustomElement);
const customElementInstance = new CustomElement();
document.body.appendChild(customElementInstance);
const devConsole = document.getElementById("dev_console"); //This is a simple div
if ("customElements" in window) {
devConsole.innerHTML = `custom Elements are supported`;
} else {
devConsole.innerHTML = `custom Elements are not supported`;
}
Surprisingly it works on the QT WebEngine browser exactly same as Edge/Chrome, the output image is shown below.
Let me know if you need me to execute any code to identify the reason, when I googled about this, it was mentioned that even if a browser supports custom elements, it might not support all functionality and it is better to check it specifically like if ('attachShadow' in HTMLElement.prototype)
You are correct. Checking for customElements
is a better test. It does appear that custom elements are supported, indeed. It could be the lack of shadow DOM support. What does "attachShadow" in HTMLElement.prototype
return?
Can you install handlers to capture console output (see link I sent previously) so that we could get an idea of where the failure is?
I can confirm that shadow DOM is being supported as "attachShadow" in HTMLElement.prototype
does return true
.
I coded C++ to capture logs using the dev console (Thanks for the link). Initially I do not get any errors (Hence I assumed that there were no errors, earlier), but after few seconds I get the following error for the "Getting started" html code.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>untitled</title>
<script defer src="//unpkg.com/mathlive"></script>
</head>
<body>
<math-field>x=\frac{-b\pm \sqrt{b^2-4ac}}{2a}</math-field>
</body>
</html>
Ah, if it's unable to load the library, that would explain why the mathfield does not render, indeed.
I would try to add a prefix to the URL, i.e. <script defer src="https://unpkg.com/mathlive"></script>
. If your document is local and has a file://
URL, the URL without the prefix would be resolve to file://unpkg.com/mathlive
and that may be while its failing.
If this doesn't work, you can copy the necessary files locally. They are in the dist
folder in the distribution available on npm
.
<script defer src="https://unpkg.com/mathlive"></script>
did solve the loading error.
However, I encountered a series of errors:
globalThis
. Object.fromEntries
.window.queueMicrotask
. I added polyfill for these to fix the issues.
<script>
if (typeof globalThis === "undefined") {
(function () {
Object.defineProperty(Object.prototype, "__magic__", {
get: function () {
return this;
},
configurable: true,
});
__magic__.globalThis = __magic__;
delete Object.prototype.__magic__;
})();
}
if (!Object.fromEntries) {
Object.fromEntries = function (entries) {
return entries.reduce(function (obj, entry) {
obj[entry[0]] = entry[1];
return obj;
}, {});
};
}
if (!window.queueMicrotask) {
window.queueMicrotask = function (callback) {
Promise.resolve().then(callback);
};
}
</script>
Now, there are no errors in the console. However, I am facing issues with CSS I believe.
The underline for division is missing.
The keyboard is squished.
Hmmm... It looks like the stylesheet may not be applied at all to the mathfield. The issue with the keyboard sounds like it might be due to a lack of support for container queries.
You are right. The QTWebEngineView browser doesn't support container queries. Is there any way I can fix it? polyfill, perhaps?
Container queries are notoriously difficult to polyfill, but maybe there's a solution out there.
Okay, Thanks Arnog!
Closing
Description
mathfield element is unrenderable in the browser provided by QT 5.12.7 framework(using QWebEngineView class).
Steps to Reproduce
Create the html file with the template code from getting started page of cortexjs.io website.
Use this file to render the html in QT browser (The browser that is provided by QT 5.12.7 framework, using QWebEngineView class). The following is the cpp code that renders the content of the html file in a browser window.
Actual Behavior
The math-field element is not rendered completely, only plain text of the latex expression is rendered.
Expected Behavior
Render the mathfield element. The following image is the output when run on browsers like Edge and Chrome.
Environment
MathLive version: 0.95.5
Operating System: Windows 10
Browser: Browser shipped with QT 5.12.7 framework (QWebEngineView); I have inserted its details below.