Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

defaultView is null (Firefox and Chromium / chart.js 4.3)

Open denis-migdal opened this issue 2 years ago • 3 comments

Expected behavior

Code running without errors.

Current behavior

When executing code, the following error occurs :

Uncaught TypeError: element.ownerDocument.defaultView is null
    getComputedStyle helpers.segment.js:2161
    getStyle helpers.segment.js:2163
    readUsedSize helpers.segment.js:2351
    initCanvas chart.js:3227
    acquireContext chart.js:3381
    Chart chart.js:5602

Reproducible sample

None

Optional extra steps/info to reproduce

No response

Possible solution

Rewrite the function getComputedStyle in "chart.js/dist/chunks/helpers.segment.js:2161" as follow :

const getComputedStyle = (element)=>element.ownerDocument.defaultView?.getComputedStyle(element, null) ?? { getPropertyValue: () => null };

Context

I had a code that worked, then I upgraded Chart.js npm package.

chart.js version

v4.3.0

Browser name and version

Firefox 113.0.2 / Chromium 114.0.5735.106

Link to your project

No response

denis-migdal avatar Jun 18 '23 15:06 denis-migdal

Related issues :

  • https://github.com/chartjs/Chart.js/issues/5300
  • https://github.com/chartjs/Chart.js/issues/1032

denis-migdal avatar Jun 18 '23 15:06 denis-migdal

Also running into this issue with the desktop GUI framework, Sciter.js

Downgrading to 3.x fixed it.

yourWaifu avatar Jul 05 '23 20:07 yourWaifu

I have the same issue

masylum avatar Sep 23 '25 20:09 masylum