r0man / cljs-http

A ClojureScript HTTP library.
582 stars 93 forks source link

jsonp throws exception due to goog.net.Jsonp api changes #124

Closed vladkotu closed 5 years ago

vladkotu commented 5 years ago

Attempt to get data using cljs-http.client/jsonp throws an exception:

Uncaught TypeError: this.uri_.cloneWithParams is not a function
    at goog.net.Jsonp.send (jsonp.js:229)
    at Object.cljs_http$core$jsonp [as jsonp] (core.cljs:125)

Seems like it caused by these changes In short - goog.net.Jsonp expect uri to be goog.html.TrustedResourceUrl (string of goog.Uri were valid before)

Potentially could be fixed by changing how url is build from request here, something like this:

;; ↓ new imports
[goog.html TrustedResourceUrl]
[goog.string Const]

(let [channel (async/chan)
      ;; ↓ trusted url insted of just url
      trusted-url (->> request
                       (util/build-url)
                       Const/from
                       TrustedResourceUrl/fromConstant)
      jsonp   (Jsonp. trusted-url callback-name)]
  (.....))
vladkotu commented 5 years ago

looks like it is reproducible only in my local env (shadow-cljs uses very latest version of org.clojure/google-closure-library) hence closing this issue

realgenekim commented 4 years ago

Hi, @vladkotu — I think I'm having the same problem, using shadow-cljs. Thanks for determining what is causing it. How were you able to resolve the problem? Many thanks!!!

Here is the exact error from a browser REPL:

=> (cljs-http/jsonp "https://publish.twitter.com/oembed?url=https://twitter.com/realgenekim/status/1223341376475222020&omit_script=true")
TypeError: this.uri_.cloneWithParams is not a function
    at goog.net.Jsonp.send (/js/iphone-compiled/cljs-runtime/goog.net.jsonp.js:65:23)
    at Object.cljs_http$core$jsonp [as jsonp] (/js/iphone-compiled/cljs-runtime/cljs_http.core.js:326:23)
    at cljs_http$core$request (/js/iphone-compiled/cljs-runtime/cljs_http.core.js:455:23)
    at eval (/js/iphone-compiled/cljs-runtime/cljs_http.client.js:219:103)
    at eval (/js/iphone-compiled/cljs-runtime/cljs_http.client.js:392:103)
    at eval (/js/iphone-compiled/cljs-runtime/cljs_http.client.js:485:103)
    at eval (/js/iphone-compiled/cljs-runtime/cljs_http.client.js:118:103)
    at eval (/js/iphone-compiled/cljs-runtime/cljs_http.client.js:129:182)
    at eval (/js/iphone-compiled/cljs-runtime/cljs_http.client.js:310:103)
    at eval (/js/iphone-compiled/cljs-runtime/cljs_http.client.js:328:182)
vladkotu commented 4 years ago

Hi @realgenekim All i needed was to call jsonp endpoint once a while. No other network interactions... so i just wrote custom jsonp function for myself. Setting google closure lib version explicitly in your project should help, however i'm not sure shadow-cljs will handle such downgrade smoothly. Anyway I would better post an issue in shadow-cljs project