mermaid-js / mermaid

Generation of diagrams like flowcharts or sequence diagrams from text in a similar manner as markdown
https://mermaid.js.org
MIT License
72.66k stars 6.62k forks source link

Mermaid v10.9.0 cannot be injected into Chrome browser extensions #5383

Open simov opened 8 months ago

simov commented 8 months ago

Description

The introduction of Katex in v10.9.0 most likely introduced characters that are not encoded properly into the build.

When I try to inject Mermaid v10.9.0 into a Chrome browser extension I get the following error:

Could not load file 'mermaid.min.js'. It isn't UTF-8 encoded.

At first glance it looks like the file is indeed encoded with UTF-8, but when I tried to convert it using a tool available on Linux:

iconv -f UTF-8 -t US-ASCII mermaid.min.js

I got

illegal input sequence at position ...

At that position I found this character:

µ

Then by removing it and running the command again, I found another one:

and so on.

Using an online converter to encode those characters I got:

This is preventing any Chromium based browser (anything except Firefox) to inject Mermaid v10.9.0, I tested with Chrome and Opera, Firefox does not complain about those characters.

Steps to reproduce

A simple Chrome extension can be created to reproduce this issue:

manifest.json

{
  "manifest_version": 3,
  "name"            : "Inject Mermaid v10.9.0 Bug",
  "version"         : "1",
  "description"     : "Chromium based browsers cannot inject Mermaid v10.9.0",

  "background" : {
    "service_worker": "background.js"
  },

  "permissions": [
    "scripting"
  ],

  "host_permissions": [
    "file:///*",
    "*://*/"
  ]
}

background.js

console.log('background')

chrome.tabs.onUpdated.addListener((id, info, tab) => {

  if (info.status === 'loading') {

    console.log('inject')

    chrome.scripting.executeScript({
      target: {tabId: id},
      files: [
        'mermaid.min.js'
      ],
      injectImmediately: true
    }, (err) => {
      if (err) {
        console.log(err)
      }
    })
  }
})

mermaid.min.js

Needs to be v10.9.0

This extension will try to inject mermaid.min.js into any page you visit.

Screenshots

No response

Code Sample

No response

Setup

Suggested Solutions

No response

Additional Context

No response

sidharthv96 commented 8 months ago

@NicolasNewman do you know if encoding to UTF-8 during build time would cause an issue? Or should we raise the issue in the Katex repo?