cemerick / austin

The ClojureScript browser-REPL rebuilt stronger, faster, easier.
510 stars 31 forks source link

js/document.write hangs, js/console.log returns nil, js/alert works #32

Closed txrev319 closed 10 years ago

txrev319 commented 10 years ago

With apologies for posting 4 questions in < 4 hours:

cljs.user> (js/alert "Hello World") ;; works fine

cljs.user> (js/console.log "Hello World") ;; returns nil, does not see anything in Chrome's console

cljs.user> (js/document.write "Hello World") ;; hangs, needs to ctrl-c + reload browser

Anyone else run into these problems? And if so, how to resolve them.

cemerick commented 10 years ago

Try (.log js/console "foo") and (.write js/document "foo").

txrev319 commented 10 years ago

Same problem

(.log js/console "Hello") ;; returns nil, nothing happens

(.write js/document "Hello") ;; hangs
txrev319 commented 10 years ago

What information can I provide to be of use?

(I realize what I have provided is useless for debugging. However, I'm not familiar with cljs-bcrepl debugging and do not know what to provide.)

txrev319 commented 10 years ago
cljs.user=> js/document.URL
"http://localhost:3002/794/repl/start?xpc=...blahblahblah..."

Correct me if I'm wrong. This means when I do (.write js/document), I'm writing into the iframe not the original document. Simiiarly, when I do (.log js/console) I'm logging into the console of the iframe and not the main document.

Is there a way to retrieve the "main document" that the iframe is embedded into?

Thanks!

txrev319 commented 10 years ago

So I'm trying

js/parent

And I'm getting the following problem:

cemerick.austin is running on localhost:3002
webserver is running on localhost:3000

Thus, I'm getting a cross-domain iframe issue. Is there a way to put some javascript in my webpage to say "allow stuff from localhost:3002" ?

Thanks!

txrev319 commented 10 years ago

With apologies for spamming the issue tracker, I believe the answer is:

http://stackoverflow.com/questions/5008944/how-to-add-an-access-control-allow-origin-header
cemerick commented 10 years ago

You have multiple issues going on. First, I cannot reproduce any problem with these expressions:

js/parent
(.log js/console "foo")

They produce the results I'd expect. Also, js/document.URL returns e.g. "http://localhost:38983/2420/repl/start", no xpc parameter.

The one thing I was able to reproduce is that:

(.write js/document "Hello World")

doesn't return: I need to interrupt the evaluation in order to get a prompt back, but the browser-repl is hosed at that point, and I need to :cljs/quit to get back to the Clojure REPL. However, the indicated text is written to the DOM. I don't have any explanations for that one; there's no cross-domain iframe problem here, since the text does appear, but there's definitely something about that expression that the browser-repl (probably client-side, since no response is returned) doesn't like.

w.r.t. the other problems you're having: what version of Chrome are you using? Can you provide a project and steps to reproduce?

johnwalker commented 10 years ago

I haven't come across the other problems, but (.write js/document "aoeu") executes without termination for me as well.

This is probably because calling .write js/document overwrites the javascript in the page with

html
  head
  /head
  body
    aoeu
  /body
/html

This happens in the cljs-start template with no changes: https://github.com/magomimmo/cljs-start

Chromium 31.0.1650.57 Mozilla Firefox 26.0 CIDER 0.5.0alpha (Clojure 1.5.1, nREPL 0.2.3) [com.cemerick/austin "0.1.3"] [org.clojure/clojurescript "0.0-2127"]

txrev319 commented 10 years ago

With apologies for multiple open tickets. Is there a reason this is still open? (I.e. for my purposes it's resolved, not sure how this got re-opened.)

cemerick commented 10 years ago

Yeah, I'd like to keep it open until I have a chance to understand the document.write issue, starting with @johnwalker's theory.

johnwalker commented 10 years ago
(def n (.getElementsByTagName js/document "iframe"))
(.remove (aget n 0))

I was off. Removing the iframe is where the problem starts.

cemerick commented 10 years ago

Confirmed @johnwalker's diagnosis. Thanks!