tradingview / charting-library-examples

Examples of Charting Library integrations with other libraries, frameworks and data transports
MIT License
1.33k stars 744 forks source link

sveltekit - TypeError: this._innerWindow().widgetReady is not a function #307

Closed jakubdonovan closed 1 year ago

jakubdonovan commented 1 year ago

Bug Report

TypeError: this._innerWindow().widgetReady is not a function

It is caused by library_path: libraryPath: '../../src/lib/charting_library/';

Upon inspecting the iframe, I can see that the src attribute does indeed point to the correct file with the correct locale, but the iFrame still refuses to load. Is there anything obvious you can see here that I might have messed up?

Screenshot 2022-09-02 at 16 43 48 Screenshot 2022-09-02 at 16 44 07

Charting Library Version "CL v22.032 (internal id e2a841ff @ 2022-07-06T11:53:07.702Z)"

Desktop (please complete the following information):

To Reproduce

  1. Clone my repo https://github.com/jakubdonovan/technical_charts_sveltekit
  2. Run npm run dev in terminal
SlicedSilver commented 1 year ago

The TypeError: this._innerWindow().widgetReady is not a function error occurs when the created iframe doesn't have a valid src url, and thus the browser can't download and display the correct html file within the iframe.

The solution is to specify the library_path relative to the current pages url (as seen by the browser).

For example, if the library files are hosted at www.example.com/charting_library and the current page is www.example.com/charts/my-chart.html then the library_path should be set to either ../charting_library/ or /charting_library/.

In your case, you would probably want to serve the library files from a folder called charting_library placed inside the static folder and then use /charting_library/ as the value for the library_path.