rafaelklaessen / react-tradingview-widget

React component for rendering the TradingView Advanced Real-Time Chart Widget.
MIT License
273 stars 94 forks source link

Exception thrown if TV Idea contains private indicators #39

Open tad3j opened 4 years ago

tad3j commented 4 years ago

I'm using this widget like: <TradingViewWidget symbol={tvSymbol} widgetType="chart" chart={tv_idea_id} />

Which results in widget loading TradingView idea that was published (by me) on their WEB app (tv_idea_id is unique identifier generated on Tcreation, one can get it if he want's to share his idea as widget).

I've noticed that if I use private indicators (one needs to have access granted by indicator owner to use it) on chart of the idea, an exception is thrown (widget/chart is rendered perfectly).

Here is the exception from console:

> vendors_embed.51ec7662100beb1c5859.js:73: **GET** https://s.tradingview.com/embed/tv_idea_id/undefined/is_auth_to_get/PUB%3BDvlIWJyaxhOxGaJHALXGBG6YmRAOjRxu/1 **404**
>
> embed_published_widget.c51dad17fc88ede2cb8e.js:664 2020-01-05T02:43:41.901Z:Pine.ScriptLib:Requesting pine facade scripts failed, url: /is_auth_to_get/PUB%3BDvlIWJyaxhOxGaJHALXGBG6YmRAOjRxu/1
>
> embed_published_widget.c51dad17fc88ede2cb8e.js:575 Uncaught TypeError: Cannot read property 'indexOf' of undefined

It seems like TV widget is trying to send an additional request (since pine script, TV's scripting language is mentioned I realized that it must be something with indicator....so I tried loading idea with public indicators only and exception is gone) but it's failing with 404, because it seems like one option is undefined.

I've been looking through TV's package where ..../tv_idea_id/**undefined**/is_auth_to_get/... could be coming from but I've only found these lines in TV's widget:

var url = this.options.mobileStatic && this.isMobile ? TradingView.host + "/embed-static/" : TradingView.host + "/embed/";
//url = https://s.tradingview.com/embed/tv_idea_id
var queryString = "?method=script" + (this.options.locale ? "&locale=" + encodeURIComponent(this.options.locale) : "");
... src="' + url + this.options.chart + "/" + queryString + "&" + TradingView.generateUtmForUrlParams(this.options) + '" ...

...so obviously the URL returning 404 is not generated here. I think TV widget fires additional requests after the widget has loaded (widget allows drawing, which would allow access to private indicator, so I guess they would want to prevent such abuse).

I also tried searching for is_auth_to_get but I can't find it anywhere on the internet (Google let me down :/ ).

Did I miss any parameters that should be passed in to this widget or it may be an edge case that is not handled?