This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-05-17
Channels
- # architecture (14)
- # aws (4)
- # aws-lambda (2)
- # beginners (66)
- # cider (63)
- # clara (39)
- # cljsjs (4)
- # cljsrn (3)
- # clojure (111)
- # clojure-berlin (5)
- # clojure-italy (17)
- # clojure-losangeles (1)
- # clojure-nl (4)
- # clojure-uk (93)
- # clojurescript (19)
- # core-async (60)
- # cursive (13)
- # datomic (22)
- # devcards (2)
- # dirac (4)
- # duct (44)
- # emacs (18)
- # fulcro (1)
- # graphql (10)
- # jobs (13)
- # jobs-discuss (27)
- # lumo (1)
- # mount (1)
- # off-topic (22)
- # om-next (1)
- # onyx (16)
- # philosophy (3)
- # planck (4)
- # precept (34)
- # re-frame (66)
- # reagent (6)
- # ring (2)
- # ring-swagger (1)
- # shadow-cljs (333)
- # specter (8)
- # tools-deps (4)
- # vim (15)
- # yada (1)
had anyone tried to use shadow-cljs to create chrome extensions?
I'm trying to create a developer tool there, but the connection doesn't work, it's trying to use a path relative to the extension, which ends up like this:
shadow.cljs.devtools.client.browser.js:811 WebSocket connection to '' failed: Error in connection establishment: net::ERR_NAME_NOT_RESOLVED
is there a way to force the URL for the websocket to be used as localhost instead of relative to page?
got it, closure defines 🙂
:closure-defines {shadow.cljs.devtools.client.env/devtools-url ""}
after more setup, new issue:
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' blob: filesystem: chrome-extension-resource:". Either the 'unsafe-inline' keyword, a hash ('sha256-8QW/FL/JEeHNL6TDE0m/ACLlRnGNJ8rr574pBcCZ1hM='), or a nonce ('nonce-...') is required to enable inline execution.
that happens when shadow tries to reload the files
I tried adding "content_security_policy": "'unsafe-inline'",
to the manifest, but chrome doesn't allow that =/
any ideas on how to get around that?
another issue regarding chrome, I need to compile and run things also in content scripts, and there it's pretty hard to read content dynamically, I'm seeing by the docs that shadow doens't use other compilation modes in dev, but I really need something like :whitespace
, or anything that outputs everything in a single file, is there a way to do this in dev mode?
@lilactown this was a bug in the closure compiler. the latest shadow-cljs version has the latest closure so try that
@wilkerlucio :devtools {:devtools-url ...}
is shorter or :devtools {:use-document-host false}
should also work
@wilkerlucio I changed the eval method in 2.3.23
and this seems to work then https://github.com/thheller/shadow-cljs/blob/master/out/chrome-ext/manifest.json#L10
took the default CSP rules from https://developer.chrome.com/apps/contentSecurityPolicy and added script-src: 'self' 'unsafe-eval';
only did the basic background.js test though. that loads fine and live-reload, REPL work
@thheller awesome! now the reload is working on background and on the devtool 🙂
but I noticed a few things after updating (I was in 2.3.21
before):
- my builds now seem to be starting one by one (I run 4 builds at once, so the startup got noticable slower)
- the regular browser devcards build, it tries to use my IP directly and it didn't connected, I had to set the :devtools-url
manually for it, while before it worked without setup
thanks
and about the content-script page, you have any idea what we can do to work there?
the loads seems to fail completely there, the content-script permission is weird
in the past I used to work in dev mode using :whitespace
compilation for it so it loads on a single file
now it's just a bunch of:
09:41:46.304 main.js:3027 GET 404 (Not Found)
(anonymous) @ main.js:3027
env.load @ main.js:3020
(anonymous) @ main.js:3065
09:41:46.306 main.js:3027 GET 404 (Not Found)
(anonymous) @ main.js:3027
env.load @ main.js:3020
(anonymous) @ main.js:3065
09:41:46.307 main.js:3027 GET 404 (Not Found)
(anonymous) @ main.js:3027
env.load @ main.js:3020
(anonymous) @ main.js:3065
09:41:46.307 main.js:3027 GET 404 (Not Found)
(anonymous) @ main.js:3027
env.load @ main.js:3020
(anonymous) @ main.js:3065
09:41:46.308
content-script
is when you want a chrome extension to inject code in the user page
on manifest.json
is like this:
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["js/content-script/main.js"],
"run_at": "document_start"
}
],
I wrote some about it in the past, because figwheel also didn't worked good for it: https://medium.com/@wilkerlucio/setting-up-figwheel-for-chrome-extensions-content-scripts-f1631d8e782a
I wasn't sucessful on making it work proper, but there is some info about loading there
just to clarify: this is for javascript that will be injected into any random page? meaning pages not written by you?
yes, correct
I could add a :dev
thing that only outputs a single file so the debug loader is not used
ok, it's reasonable, because currently it just doesn't work as dev at all, I would have to manually re-trigger a release everytime on every update
if we can it just re-compiling in a single file automatically, would help a lot
but I'm wondering, why can't the REPL work there?
when injected into the page you do not own the global scope so the potential for conflicts is high
its also a bit scary since you are technically giving the page you inject into access to your REPL
but on content scripts you kind have your own context, and you can inject those variable and reliably access then
I'm making a fulcro-inspect version that runs on chrome ext / electron
so the content-script will have to hook into the fulcro tools to send information to the remote ui (that will be in a chrome devtool/electron)
they are, but they have a special context
Although the execution environments of content scripts and the pages that host them are isolated from each other, they share access to the page's DOM.
sorry I wasn't clear before, it's been a while I read that, so yeah, separated envs, shared DOM
this should be fine on manifest:
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["js/content-script/main.js"],
"run_at": "document_start"
}
],
that will make the script run on every page
for compilation I currently have this:
:chrome-content-script {:target :browser
:output-dir "shells/chrome/js/content-script"
:asset-path "js/content-script"
:closure-defines {:devtools-url ""}
:modules {:main {:entries [fulcro.inspect.chrome.content-script.main]}}}
@wilkerlucio how important is "run_at": "document_start"
to you? would document_idle
be enough?
@thheller I don't know yet, was just setting up the env, maybe document_idle
will be enough
is there a roadblock with document_start
?
nah not really. currently the debug loader tries to be smart and checks if it can use document.write
to load scripts
hehe, maybe we can have a flag for it
so we can override on content-script case
Hi! trying to do release build of project. Got this output for :target :node-script
:
var shadow$provide = {};
#!/usr/bin/env node
(function(){
...
My use case is I'd like some computation to be done at compile time and statically defined in the app.
It confused me because when developing my browser application I am able to write and use macros by default.
I was trying to follow this example: https://github.com/shadow-cljs/examples/tree/master/macros.
This is what happens: https://github.com/kennyjwilli/shadow-cljs-macros
(ns shadow-macros.core
(:require
[shadow-macros.macros :include-macros true :as macros]))
also, getting this with release build:
------ WARNING #1 --------------------------------------------------------------
File: com/cognitect/transit.js:649:8
variable module is undeclared
--------------------------------------------------------------------------------
------ WARNING #2 --------------------------------------------------------------
File: com/cognitect/transit/impl/writer.js:256:8
variable isObject is undeclared
--------------------------------------------------------------------------------
------ WARNING #3 --------------------------------------------------------------
File: com/cognitect/transit/types.js:384:70
variable Buffer is undeclared
--------------------------------------------------------------------------------
@thheller just haven't seen this warnings with boot-cljs and :advanced optimizations. Trying to figure out why some parts of my code in release silently doesn't work 🙂 Thank you!
right, that might be the case: haven't seen default params enabled in boot for cljs compilation
your example tries to skip the "additional" .cljs
file but it is very important to have that
it is not a requirement but it saves you from dealing with :require-macros
or :include-macros
all over the place
@zarkone CLJS by default doesn't enable those checks either. its just something shadow-cljs does. if you want to find out why things don't work shadow-cljs check your-build
might help
Yep that works. Wow, that clears a lot up. Thank you. I think this bit of information is important enough to include in the documentation somewhere.
There's this https://clojurescript.org/guides/ns-forms. But doesn't really suggest a pattern.
I'd even argue that makes things more confusing because it introduces you to all the different ways you can use macros 🙂
@thheller actually, I've known that I can get rid of :require-macros
from recent defn
podcast where you've talked about it 😄
Exactly. That's what it needs. I don't have any reason to care about all that other stuff.
and if you want to emit code that uses other namespaces the CLJS ns can require those to ensure they are loaded
people might end up trying to use random CLJ libraries and wonder why they don't work
@wilkerlucio the problem with a single output file is source maps. debugging without those is horror but they get waaaaaaaaaaaaay too large and slow
@thheller yeah, not cool, after those changes is the regular :none working?
a) sucks because certain lifecycle events fire before the code is loaded eg. chrome.runtime.OnInstalled
b) sucks because chrome complains and you must reload browser extension manually on each code change
unfortunately https://groups.google.com/d/msg/google-chrome-developer-tools/7mONVX1IAYo/Psq3uIBoCgAJ was never fixed
gotcha, thanks for the clarification, this is a tricky one
How do prevent the clojure.spec exception from being thrown due to the non-conforming NS form from the JS string requires? I'm trying :jvm-opts ["-Dclojure.spec.compile-asserts=false"]
in shadow-cljs.edn but it's not seeming to be working. is there a standard way to address this?
getting a massive spec error relating to an invalid NS form when I try to eval the NS form in the repl. It works fine outside of the repl connection. I assumed this was due to the (:require ["js-lib" :as js-lib"] ...)
string form causing issues but I could be wrong
CLJS REPL should work fine for this but you might be trying to eval this in CLJ which won't work
@wilkerlucio I will think about this for a bit. you can get it sort of working now by setting
:chrome-content-script
{:target :browser
:output-dir "shells/chrome/js/content-script"
:asset-path " "
:modules {:main {:entries [fulcro.inspect.chrome.content-script.main]}}
:devtools
{:devtools-url ""
:http-root "shells/chrome/js/content-script"
:http-port 8020}}
:browser
is complete overkill for this though.
:chrome-ext
{:target :chrome.content-script
:output-to "out/chrome-ext/background.js"
:entry demo.chrome-bg}
@thheller thank you very much for looking so quickly on it, I’ll try those as soon as I get home today
@wilkerlucio good timing I guess since I wanted to try some ideas for a chrome extension for shadow-cljs anyways 🙂
in the beginner's tutorial https://medium.com/@jiyinyiyong/a-beginner-guide-to-compile-clojurescript-with-shadow-cljs-26369190b786 It mentions you have to link the index.html to the target folder. Is there a way to do this as part of the build process in the shadow-cljs.edn file?
@thheller I'm still seeing the Uncaught TypeError: Cannot call a class as a function
error in shadow-cljs 2.3.22
@thheller the version with the chrome updates is released?
I think that for now, I can just delete the _classCallCheck(this, Source);
from the source of the npm module
is there a way for me to vendor the npm module outside of node_modules/
? I see that I can redirect what it resolves to, but the only options I see are either :global
or :npm
. I'd like to stick it in another dir that I can commit to source control
@lilactown what was your error again?
maybe not though .. the error was different https://github.com/thheller/shadow-cljs/issues/248
this should be fixed in closure 20180506. maybe you have an older closure dependency?
as for npm fixing I would suggest taking the node_modules/graphql
directory and publish it under @lilactown/graphql
or so
@theeternalpulse I don't recommend that setup. better use https://github.com/shadow-cljs/quickstart-browser
Ah thanks, it is linked in the main website, so I figured it was recommended. Also there's a discrepancy in the namespaces created and built in that article
@thheller sorry bothering, I can't find the updates with the chrome things, did you pushed those?
@wilkerlucio which updates? I didn't release anything related to that yet no
ah, gotcha, no worries, I just had assumed you pushed, my bad
hehe I can crash chrome by pressing ctrl+shift+e
trying to profile my background page 😛
Would it matter if I had clojurescript in my lein deps? I'm using the lein integration
didn't tried yet, still not home, was just trying to check it before you might go sleep 🙂
when you announced the :target :chrome.content-script
I though it was out
@wilkerlucio just pushed the basic version in master
:chrome-bg
{:target :chrome-extension
:output-to "out/chrome-ext/background.js"
:entry demo.chrome-bg}
:chrome-content
{:target :chrome-extension
:output-to "out/chrome-ext/content-script.js"
:entry demo.chrome-content}
cool, but isn't the background settings different from the content-script one?
I mean, the background and devtools parts were working perfectly here
hum, so the plan is for :chrome-extension
for all, I would guess content-scripts would have a different setting compared to background/popups/devtools
, I guess we will figure that soon
yeah, sometimes chrome forces you do make a lot of round before doing something, what you can do in background is different from what you can do on a popup page, that's also different from a content-script...
a different build for each seems like a bit of overkill but probably the only option
for compilation I think 2 should suffice, one for content-script, and another for the rest
because the content-script is the one that has a bit difference in security things
the other ones vary mostly on which chrome API's you can access, but that's not a compilation concern
but the REPL for background and pages is working already, isn't it?
if I can sort out this source map issue then all targets could technically use the simplified :chrome-extension
what kinds of things the :browser
does that we don't need there?
agreed
> The list of JavaScript files to be injected into matching pages. These are injected in the order they appear in this array.
the problem is happening now is at initial load, or to refresh code after?
yeah, that one 🙂
so there are no source-maps at all?
does that solve the problem on reloading code after?
not related to that at all. that all works without issues in theory. didn't enable it yet
yeah, and that's fine
would be nice to do some changes before releasing, but that is a deploy process problem
@wilkerlucio master
now has source maps and REPL but not live-reload doesn't work
thank you very much, I just got home, so time to try and hack 🙂
does shadow yet support continuously running tests? i know that’s not a … flavor… that people in the clj world like, but it would ease a lot of my coworker’s anxieties
looks like the default node target just spits out a file, then you can run it with node automatically with :autorun . i could probably setup some node watcher to keep reading that file for changes and rerun on change, but I dont want to duplicate effort
i mean that if I run shadow compile test
with :autorun true
it will launch the node ./out/node-tests.js
and spit the results, but then the node process dies… is there a built in way to keep rerunning that node command every time node-tests.js
changes?
that’s exactly what i was looking for, i’m just being stupid (forgot watch was a thing)
@thheller I tried adding the content script here now, it loads, but I'm getting errors: https://www.dropbox.com/s/hevvi7n2lps765i/Screenshot%202018-05-17%2019.56.34.png?dl=0
ps: I'm using the .23
version yet, not sure how to use it shadow from master
yeah thats the conflict stuff I mentioned. your injected code "replacing" the actual code in the page
ah, I'm using from the npm run version
I was reading the code on repo, I guess you do some scripting to make a release (because trying to install directly from git didn't work, there is no package.json on the root)
so I just override my local version, right?
I see it still compiles one by one, would you like me to create an issue so we don't forgot about the paralell initial compilation?
[:chrome-content-script] Build failure:
invalid require
{:entry [fulcro.inspect.chrome.content-script.main]}
ExceptionInfo: invalid require
clojure.core/ex-info (core.clj:4739)
clojure.core/ex-info (core.clj:4739)
shadow.build.resolve/resolve-require (resolve.clj:492)
shadow.build.resolve/resolve-require (resolve.clj:482)
shadow.build.resolve/resolve-entry (resolve.clj:496)
shadow.build.resolve/resolve-entry (resolve.clj:495)
clojure.lang.PersistentVector.reduce (PersistentVector.java:341)
clojure.core/reduce (core.clj:6747)
the :entry
is to be a namespace, right?
yeah, I tried to be smart and just move the code, that's what I get, hehe