admin管理员组

文章数量:1125086

I'm working on a Google Chrome extension and I want to inject a Chart.js chart into an existing website. I have the following scenario:

  1. I need to use Chart.js to render a chart dynamically.

  2. The chart should be injected into the current page via the content.js script of my Chrome extension.

  3. The target website does not have Chart.js, so I need to load it via my extension and inject the chart into the page.

Here’s my setup:

  • Manifest version 3
  • The extension uses a content script (content.js).
  • The content script is supposed to run on a specific website, and I want to add the chart after the page loads.

What I’ve tried so far:

Using chrome.scripting.executeScript to inject the Chart.js script into the page. Trying to create a element within content.js and then render the chart. However, I'm encountering issues with:

  • Properly loading the Chart.js library in the content script.
  • Ensuring the canvas is rendered correctly on the webpage.
  • Handling dependencies between the content script and Chart.js.

How can I load Chart.js in a content script and inject it into an existing webpage without causing conflicts?

本文标签: