Fork me on GitHub
#shadow-cljs
<
2022-03-28
>
raymcdermott13:03:10

DOMException: The operation is insecure.
The above error occurred when loading "shadow.cljs.devtools.client.browser.js". 

raymcdermott13:03:09

This message is from an app in the browser built with release app

raymcdermott13:03:06

Any idea why this is being included in the build?

thheller16:03:41

@raymcdermott unless you are including it manually somehow this should not be part of a release build. neither should a file of that name? you sure you are loading the release build files?

😬 1
raymcdermott08:03:03

It was a caching problem. Sorry.

thheller16:03:28

release builds only have one file per module, not one file per namespace. unless this is a :npm-module build?

Pavel Klavík16:03:50

Hi, I am trying to get my project working on MacOS and I have discovered the following strange behaviour. When I connect to Shadow-cljs nREPL and switch to the browser target, I can run (js/console.log "Test") fine, but when running (js/alert "Test"), I get the following error: Execution error (ReferenceError) at (<cljs repl>:1). alert is not defined => :repl/exception! Similarly for js/document and others.

thheller16:03:24

do you use a web worker? you might be connected to the worker in that case?

Pavel Klavík16:03:38

yes, I am running some web workers

thheller16:03:48

you can see the runtime ids listed at http://localhost:9630/runtimes

thheller16:03:13

and pick which one to connect to via (shadow/repl :the-build-id {:runtime-id that-id-number})

Pavel Klavík16:03:24

yes, this works fine

Pavel Klavík16:03:34

any way to set up the default runtime-id?

thheller16:03:28

no, other than either picking the first or last connected

thheller16:03:43

defaults to picking the first one connected and staying with that

Pavel Klavík16:03:51

can I list all build ids in REPL?

thheller16:03:30

(shadow/repl-runtimes :the-build-id)

Pavel Klavík16:03:28

ok, cool, I can write some wrapper for that which will connect me to the correct REPL

Pavel Klavík16:03:44

plus it is useful to be able to search this when running in multiple browsers, etc.

borkdude19:03:07

What target is recommended when you want to build a chrome extension? I'm trying with browser but I got:

if (!doc) {
    throw new Error("browser bootstrap used in incorrect target");
  }

thheller19:03:20

:target :chrome-extension I guess

thheller19:03:27

or maybe nowadays :target :esm is better

thheller19:03:49

haven't looked at browser extensions for many years now. dunno what that looks like now

borkdude19:03:24

I have tried both already. :esm gives me "cannot import module" or something and :chrome-extension gives me a "Cannot find manifest.edn" stacktrace in the console.

thheller19:03:30

that is not enough information to figure out the context of those errors

borkdude19:03:59

The ESM route I've already read some things about, it consists of workarounds, but I think that because the compiled .js loads other .js files makes it more complicated. I could just work with optimizations simple maybe. The other one, I'll reproduce now.

borkdude19:03:13

I'll post a stacktrace of :chrome-extension in a thread here.

borkdude19:03:18

[:modules] Configuring build.
[:modules] Build failure:
FileNotFoundException: manifest.edn (No such file or directory)
	java.io.FileInputStream.open0 (FileInputStream.java:-2)
	java.io.FileInputStream.open (FileInputStream.java:219)
	java.io.FileInputStream.<init> (FileInputStream.java:157)
	 (io.clj:229)
	 (io.clj:229)
	 (io.clj:69)
	 (io.clj:165)
	 (io.clj:165)
	 (io.clj:69)
	 (io.clj:102)
	 (io.clj:86)
	clojure.core/apply (core.clj:669)
	clojure.core/slurp (core.clj:7009)
	clojure.core/slurp (core.clj:7009)
	shadow.build.targets.chrome-extension/configure (chrome_extension.clj:59)
	shadow.build.targets.chrome-extension/configure (chrome_extension.clj:48)
	shadow.build.targets.chrome-extension/process (chrome_extension.clj:310)
	shadow.build.targets.chrome-extension/process (chrome_extension.clj:305)
	clojure.lang.Var.invoke (Var.java:384)
	shadow.build/process-stage/fn--14625 (build.clj:161)
	shadow.build/process-stage (build.clj:158)
	shadow.build/process-stage (build.clj:150)
	shadow.build/configure (build.clj:389)
	shadow.build/configure (build.clj:274)
	shadow.cljs.devtools.server.worker.impl/build-configure (impl.clj:205)
	shadow.cljs.devtools.server.worker.impl/build-configure (impl.clj:156)
	shadow.cljs.devtools.server.worker.impl/do-config-watch (impl.clj:571)
	shadow.cljs.devtools.server.worker.impl/do-config-watch (impl.clj:565)
	shadow.cljs.devtools.server.util/server-thread/fn--15932/fn--15933/fn--15941 (util.clj:269)
	shadow.cljs.devtools.server.util/server-thread/fn--15932/fn--15933 (util.clj:268)
	shadow.cljs.devtools.server.util/server-thread/fn--15932 (util.clj:241)
	java.lang.Thread.run (Thread.java:829)

borkdude19:03:26

Configuration:

borkdude19:03:27

{:deps true
 :dev-http {7778 ["classpath:public"]}
 :builds
 {:modules
  {:js-options {;; don't bundle any npm libs
                :js-provider :import}
   :compiler-options {:infer-externs :auto}
   :target :chrome-extension
   :output-dir "resources/public/js"
   :modules
   {:nrepl_extension {:init-fn nrepl-extension.core/init}
    }
   :build-hooks [(shadow.cljs.build-report/hook
                  {:output-to "report.html"})
                 ]}}}

thheller19:03:00

uhm that looks like you took a :esm config and just changed :target

thheller19:03:03

thats not how that works

thheller19:03:44

there are no docs but that issue has all the info you should need

thheller19:03:23

there is also a sample manifest.edn it is looking for

borkdude19:03:31

> thats not how that works Oops sorry, I kind of relied on the spec checking that shadow-cljs does in various other places :)

thheller19:03:36

btw :compiler-options {:infer-externs :auto} has been the default for quite some time now. you never need to set it.

thheller19:03:07

also the build-report hook won't work either

borkdude19:03:37

that's all fine with me, I just started with an ESM build I already had

thheller19:03:28

4 years ago .. so I don't expect chrome to still accept this at all

borkdude19:03:40

thanks, I'll check it out

borkdude19:03:30

which is a sign that apparently it still worked in 2020 I mean :)

thheller19:03:10

well the shadow-cljs side didn't change, so that'll work 😉

thheller19:03:38

but I believe chrome has a new manifest version that is apparantly different but I didn't look at that at all yet

borkdude19:03:44

yes, they have v3 now :/

borkdude19:03:20

I'll try optimizations simple with esm first...

borkdude19:03:44

since I already noticed some deprecation warnings with a v2 extension I wrote in JS once :(

borkdude19:03:16

I can live with no REPL to get this bootstrapped. I'm developing an nREPL server in the browser...

👀 1
thheller19:03:59

nrepl server in the browser?

borkdude19:03:32

yeah, it's an experiment for now

borkdude19:03:01

so I need to open a tcp port in the browser and the only way seems to make an extension

thheller05:03:11

I just looked over some of the docs of the chrome extension stuff

thheller05:03:18

:target :esm is absolutely the way to go now and is fully supported. just may need to set "type":"module" in some places apparently

thheller05:03:20

the article you linked is from Dec 27, 2017 so not accurate anymore

thheller05:03:36

it should also properly support modules loading other modules so all the extra hacks :chrome-extension did to sometimes create standalone files should not be needed anymore

thheller05:03:29

just content-scripts still seem to be a bit more limited, although might just work too

thheller06:03:12

tcp server support however seems to be deprecated and removed soon

borkdude10:03:36

@U05224H0W I will try to get back on the ESM track, but I haven't seen an up to date example with a service_worker .js script that directly works as an ES6 module. Have you?

borkdude10:03:58

"type": "module" isn't supported as part of the v3 manifest, it says unknown key

borkdude10:03:12

Ah:

"background": { "service_worker": "bg.js", "type": "module" },

borkdude11:03:09

Got a basic setup working now

borkdude11:03:25

still manifest v2, so yes, this might soon disappear :/

thheller17:03:15

> This API is part of the deprecated Chrome Apps platform. Learn more about migrating your app.

borkdude19:03:55

Yes, I've already abandoned the whole idea

pinkfrog13:05:28

Yup. Looks like the case:

pinkfrog13:05:02

Chrome web store does not allow publish manifest v2 extension from early this year.

pinkfrog13:05:15

@U04V15CAJ How’s your progress on your chrome extension?

borkdude13:05:46

@UGC0NEP4Y I stepped away from that since extensions do not allow you to open TCP ports. I solved my problem in a different way that doesn't require an extension