(failed) Attempts to inject cljs repl into 3rd party webpage

25 views
Skip to first unread message

Sigmund Tzeng

unread,
Aug 13, 2019, 12:40:36 AM8/13/19
to ClojureScript
Hi there,

Here are my steps to inject cljs repl into 3rd party webpage:

1. inject the following line via "Custom JavaScript for websites"

 (function(){var d=document;var s=d.createElement('script');s.src='https://localhost:8090/js/main.js';d.body.appendChild(s);})()

2. *.edn file:

;; shadow-cljs configuration
{:source-paths
 ["src/dev"
  "src/main"
  "src/test"]

 :dependencies
 [[reagent "0.8.1"] ;[etaoin "0.3.5"]
 ]
 :ssl {} ;for shadow-cljs server, defaults to 9630 port
 :http {:port 9630
        :ssl-port 23456
        :host "localhost"} 
 :dev-http {8090 {:root "public"
        :push-state/headers {"Access-Control-Allow-Origin" "*" }}
  }
 :builds
{:frontend
  {:target :browser
   :asset-path "https://localhost:8090/js"
   :modules {:main {:init-fn acme.frontend.app/init}}
   }}}

3. modify main.js with no-cors mode

          fetch(uri, {    mode: 'no-cors'})

4. However, the browser endpoint (shown below) is never called 

wss://localhost:23456/ws/worker/frontend/.../browser

5. what am i missing here? the emacs skewer-mode seem to work just fine.
  Was wondering if DOMContentLoaded ever get fired, even so I don't know how to fix/patch it.


Thomas Heller

unread,
Aug 13, 2019, 4:10:07 AM8/13/19
to ClojureScript
You cannot really inject a shadow-cljs dev build into any arbitrary page. It is not designed for that and will potentially conflict with the page itself in bad ways.

You can set :devtools {:devtools-url "https://your.host:23456"} to overwrite where the socket is trying to connect to. The Browser console will tell if you that connect fails.

DOMContentLoaded is not used by the CLJS build, not sure why you are asking about it. If you are trying to register an event handler for it you are likely just registering it too late when it has already fired.

John Newman

unread,
Aug 13, 2019, 12:52:24 PM8/13/19
to ClojureScript
I made a thing for that here https://www.chrepl.app/

I haven't made it work with shadow-cljs yet, but that'd be an interesting option.

V/r

John
Reply all
Reply to author
Forward
0 new messages