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

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

Open
simov opened this issue Mar 13, 2024 · 1 comment
Open

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

simov opened this issue Mar 13, 2024 · 1 comment
Labels
Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect

Comments

@simov
Copy link

simov commented Mar 13, 2024

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

  • Mermaid version:
  • Browser and Version: [Chrome, Edge, Firefox]

Suggested Solutions

No response

Additional Context

No response

@simov simov added Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect labels Mar 13, 2024
@simov simov changed the title Mermaid v10.9.8 cannot be injected into Chrome browser extensions Mermaid v10.9.0 cannot be injected into Chrome browser extensions Mar 13, 2024
@sidharthv96
Copy link
Member

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect
Projects
None yet
Development

No branches or pull requests

2 participants