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

Error using toPng with extra quote in HTML #152

Open
2 tasks done
stickeegreg opened this issue Aug 18, 2023 · 0 comments
Open
2 tasks done

Error using toPng with extra quote in HTML #152

stickeegreg opened this issue Aug 18, 2023 · 0 comments

Comments

@stickeegreg
Copy link

stickeegreg commented Aug 18, 2023

Use case: description, code

If the HTML has mangled quotes, for example <div id="x""> or <div id="x class="x"> then domtoimage.toPng will emit an Event with a type of error but no message.

jsfiddle

Expected behavior

Screenshot should be produced

Actual behavior (stack traces, console logs etc)

Event
    isTrusted: true
    bubbles: false
    cancelBubble: false
    cancelable: false
    composed: false
    currentTarget: null
    defaultPrevented: false
    eventPhase: 0
    returnValue: true
    srcElement: null
    target: null
    timeStamp: 11920.099999904633
    type: "error"
    [[Prototype]]: Event

Library version

3.1.6

Browsers

  • Chrome 115
  • Firefox 116

Workaround

Removing attributes names containing " before taking the screenshot will work around the problem

document.querySelectorAll('*')
    .forEach((element) => {
        const invalidAttributeNames = element.getAttributeNames()
            .filter(name => name.includes('"'));

        for (const name of invalidAttributeNames) {
            element.removeAttribute(name);
        }
    });
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