marp-team / marp-core

The core of Marp converter
MIT License
750 stars 127 forks source link

Code block in HTML presentation issues Uncaught DOMException: Operation is not supported #370

Open vainiusd opened 3 months ago

vainiusd commented 3 months ago

Version of Marp Tool

marp-vscode 2.8.0

Operating System

macOS

Environment

How to reproduce

Any code block defined in presentation:

--- marp: true ---

``` ```

Presentation exported to HTML and viewed in mozilla.

Expected behavior

No loading/console errors.

Actual behavior

Presentation loads, but with errors. This is especially visible with a larger presentation and a mobile browser.

Browser console output:

Uncaught DOMException: Operation is not supported
    <anonymous> file:///Users/user/slides/test.html:14
    w file:///Users/vdangovas/user/slides/test.html:14
    w file:///Users/vdangovas/user/slides/test.html:14
    <anonymous> file:///Users/user/slides/test.html:14
    <anonymous> file:///Users/user/slides/[test.html:14](file:///Users/user/slides/test.html) test.html:14
    <anonymous> file:///Users/user/slides/test.html:14
    w file:///Users/user/slides/test.html:14
    w file:///Users/user/slides/test.html:14
    <anonymous> file:///Users/user/slides/test.html:14
    <anonymous> file:///Users/user/slides/test.html:14

Line 14 is <script>!function()[...]

Additional information

Public instance with these errors: https://vainiusd.github.io/marp-cheatslides/

yhatt commented 3 months ago

🚚 Transferred the issue from marp-team/marp-vscode to marp-team/marp-core because it originates from the browser-side script of Marp Core.

TL;DR: The reported errors do not cause any problems in rendering Marp slides.

yhatt commented 3 months ago

This is due to the different behavior between Firefox and Chrome when defining the Marp Core's Web Component (<marp-pre> for auto-scaling code blocks in <pre> elements) using the is attribute.

When <marp-pre> component defined (at loading slides), both browsers tries to upgrade existing <pre is="marp-pre"> elements. While upgrading, there is a difference in each browser whether the element is already recognized as <marp-pre> at the time of setting the Shadow DOM in the constructor.

In Firefox, <pre> is not yet upgraded to <marp-pre> until initialization of the custom element (constructor) is over. <pre> element cannot attach the Shadow DOM due to security reasons, so the browser raises NotSupportedError for each <pre> elements.

In Chrome, <pre> is already upgraded to <marp-pre> while running constructor of the custom element. <marp-pre> is allowed to attach custom element so any exceptions will not bring when attaching Shadow DOM.

However, they are browser-side errors that occurs when updating the definition of existing HTML elements, and they do not stop the main JavaScript thread due to the exception. The subsequent processes in the script (more reliable Web Component upgrade process, to deal with upgrade failures in Firefox and Safari) will be continue without any problems, so there are not any problems in rendering Marp slides.

yhatt commented 3 months ago

Ideas to suppress errors: