Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Kevin Walter
@lucidd
with that the bindings are usable like this
chrome.storage.Storage.local.set(Map("hello" -> "world")).foreach(println)
chrome.storage.Storage.local.get(Array("hello")).foreach(println)
Jordan Gwyn
@emanresusername
sweet! on the clock for a while, but will check it out soon as i get off!
Jordan Gwyn
@emanresusername
@lucidd got a little (lot :sweat_smile: ) derailed today. Huge :+1: on the niceness improvement on the method signatures!
and not seeing the same error in the console any (which could easily mean i was just doing something wrong to begin with :) )
kramer425
@kramer425
Hi everyone, I just found this project last week and it looks great. I set up the sample extension (slightly modified), but I can only get it to work with sbt-chrome-plugin v 0.2.1, as well as scala 11.8. Would you guys mind taking a look at my build.sbt?
Kevin Walter
@lucidd
Hey, sure if you post a link to your project I can take a look later
kramer425
@kramer425
Thanks so much Kevin, it's here: https://github.com/kramer425/SN
Kevin Walter
@lucidd
@kramer425 something like this should work
 import chrome._
import chrome.permissions.Permission
import chrome.permissions.Permission.API
import net.lullabyte.{Chrome, ChromeSbtPlugin}

lazy val root = project.in(file("."))
  .enablePlugins(ChromeSbtPlugin)
  .settings(
    name := "sn",
    version := "0.1.0",
    scalaVersion := "2.11.8",
    scalacOptions ++= Seq(
      "-language:implicitConversions",
      "-language:existentials",
      "-Xlint",
      "-deprecation",
      "-Xfatal-warnings",
      "-feature"
    ),
    persistLauncher := true,
    persistLauncher in Test := false,
    relativeSourceMaps := true,
    libraryDependencies ++= Seq(
      "net.lullabyte" %%% "scala-js-chrome" % "0.4.0" withSources() withJavadoc(),
      "com.github.japgolly.scalajs-react" %%% "core" % "0.11.3" withSources() withJavadoc(),
      "com.github.japgolly.scalajs-react" %%% "extra" % "0.11.3" withSources() withJavadoc()
    ),
    jsDependencies += "org.webjars" % "react" % "0.13.3" / "react-with-addons.min.js" commonJSName "React",
    skip in packageJSDependencies := false,
    chromeManifest := new ExtensionManifest {
      val background = Background(
        scripts = Chrome.defaultScripts
      )
      val name = Keys.name.value
      val version = Keys.version.value
      override val permissions = Set[Permission](
        API.Tabs,
        API.Management
      )
    }
  )
kramer425
@kramer425
That did it Kevin! When I previously tried to import chrome.permissions.Permission, intellij said it couldn't find it, but it's working now so that's great. Thanks so much for your help
kramer425
@kramer425
Hey guys, are content scripts the only way for an extension to modify the dom of a given tab's page?
kramer425
@kramer425
I think I answered my own question. Are content scripts on the todo for this library?
Kevin Walter
@lucidd
@kramer425 there are no direct plans for special content script support but i think the API for injecting them should already be available. You could also try to inject your extension script as content script and have some detection at the beginning if you are running as extension or as content script and execute code accordingly.
@kramer425 if you have any idea of what special content script support would look like feel free to open an issue for discussion :smile:
Jordan Gwyn
@emanresusername
@lucidd the scalajs sbt settings (really just the build.sbt in general :sweat_smile: ) are like a foreign language to me. do you know off the top of your head or have pointers for how to make this work with the scala-js-bundler plugin?
Kevin Walter
@lucidd
@emanresusername haha yeah sbt takes a little to get used to :smile: i have not used this plugin yet but https://scalacenter.github.io/scalajs-bundler/getting-started.html seems to be a good start. There is also a link to a full example project at the bottom. Hope it helps
Jordan Gwyn
@emanresusername
I'll try to make a minimal project combining the two and see if I can nail down exactly what the conflict is
Jordan Gwyn
@emanresusername
@lucidd so for something like this
my intuition would be to run like bundlerExtension/chromeUnpackedFast::webpack and then be able to load the directory in target/chrome/unpacked-fast as an unpacked extension as expected, but there are clearly some more configuring i need to do to make that work. Does that make more sense/help clarify?
kramer425
@kramer425
@lucidd Hi Kevin, I just asked in the scala-js chat about splitting code into multiple js files. I would need another project in my build in order to do that. Since content scripts are not allowed to access any of the chrome apis, does it make more sense to keep content script creation out of the scala-js-chrome project?
Although, I would need to be able to access the messaging api
Kevin Walter
@lucidd
I think this is a similar problem to projects that have a Scala server project which needs a scalajs client project as a ressource.
@kramer425 you should be able to have two projects in sbt and use the generated Resource mechanism to copy content script into the extension. Depending on this library in your content script should not be a problem as long as you dont use anything thats not availabe in the web page. scalajs will make sure to only include what you actually use so there should be no additional cost.
kramer425
@kramer425
Thanks Kevin I'll try that. Since I can specify which websites I want the content script to run on, do you think I would include a main in it as well?
Kevin Walter
@lucidd
i think it needs a main to run if you inject it into the website but you have to look at the content script documentation
kramer425
@kramer425
Ok thanks. Do you think in CodeInjectionOptions def apply(code: js.UndefOr[String] = js.undefined, could be changed to take a js.Any or js.Function so you can pass in scala code?
Kevin Walter
@lucidd
@kramer425 that would be cool but i don't think thats possible. Chrome wants a string of javascript there is no way around that. maybe it would be possible to use a macro to pass in a scala function and have it at compile time transformed into a string of javascript but i don't think its trivial.
Simone Robutti
@chobeat

Hello, I'm a scalajs newb (and not really skilled in JS either). I'm trying to create a chrome extension using scala-js-chrome

I got a general idea on how to work with the ChromeApp API and how to create windows but I would like to actually create an extension that listens to events in all the tabs. I saw how to do this in JS through CodeInjection. My problem is that, while the wrapper wraps the corresponding call "executeScript", I don't know how to pass the actual code to execute. The options available are through a string and through a filename. ( https://github.com/lucidd/scala-js-chrome/blob/master/bindings/src/main/scala/chrome/tabs/bindings/CodeInjectionOptions.scala )

In my newbiness I have no idea how to do so through scalajs

Kevin Walter
@lucidd
@chobeat there are multiple ways you could go about this. Chrome wants either javascript as a string or a file to inject. You could just inject a plain javascript file if you want but i guess thats not what you are looking for. Alternatively you could inject your extension script itself and have some check in the main for if its running in a web page or as extension and act accordingly. The third option is to setup a multiproject sbt build where you have your extension project and your inject script project and have the extension depend on the output of the inject script project as a resource.
Simone Robutti
@chobeat
@lucidd thank you very much. I'm not sure about how to go for the second option but I will try something. Otherwise the third option seems the cleanest and I will go for it
kramer425
@kramer425
@chobeat If you get the third option to work, please let me know!
@lucidd Thanks Kevin, didn't see your last response. Hopefully Simone makes progress with using multiprojects to write content scripts in scala
kramer425
@kramer425
Hey guys, I opened up an issue for adding support for content & popup scripts. In the meantime I made a repo with three different projects in it, and a shell script that compiles them and copies over the necessary files
kramer425
@kramer425
Has anyone used Runtime.sendMessage? Runtime.sendMessage(message = "hi") is giving me an error: Error in event handler for runtime.onMessage: Error: Invalid arguments to sendMessage. at $c_Lchrome_runtime_Runtime$.sendMessage__sjs_js_UndefOr__sjs_js_Any__sjs_js_UndefOr__sjs_js_UndefOr__V that's hard to parse
Jordan Gwyn
@emanresusername
@kramer425 ^^ idk if it's exactly the same, but i hit something similar might be worth specifying some of the other args to that method
kramer425
@kramer425
Good to know thanks! I went with chrome.runtime.bindings.Runtime.sendMessage which seems to work
Aleksandr Bezhan
@alexbezhan
Hey guys. Does scala-js-chrome plugin support source maps?
Yuriy Badalyantc
@LMnet
Hi everybody. What is the status of the project? I want to use it and contribute to it, but last commit was on June and project looks abandoned.
Jordan Gwyn
@emanresusername
:+1:
Kevin Walter
@lucidd
@OleksandrBezhan i currently don't have much time to work on the project so i only merge PRs and publish new versions occasionally. I hope i have more time for it in the future but no promises sorry.
sorry wrong guy. was meant fot @LMnet
Mathieu Prevel
@mprevel
@lucidd Hi. Do you think you will have time to merge current PRs ?
Kevin Walter
@lucidd
@mprevel i found some time to look at your PR and merge them. Thank you for those contributions :thumbsup:
Mathieu Prevel
@mprevel
@lucidd thanks :)
Mathieu Prevel
@mprevel
@lucidd I created 2 PRs. One for the source map support, another to update scala 2.11.11 to scala 2.11.12.
None of them passed the CI. It seems that Travis was unable to get some dependencies... and scala itself in both PRs. So this is clearly not a problem from the PRs themselves. I don't know if there is a way to request another build. I posted on the travis gitter expecting some help on this.
The scala update from 2.11.11 to 2.11.12 was almost only to check if the build will pass (but at least, this is done).
Mathieu Prevel
@mprevel
@lucidd I re-created the PRs and everything is ok. This was a temporary network issue
Mathieu Prevel
@mprevel
@lucidd thanks for the previous merge. Do you think you'll merge the PR on source maps ? If not what could be done to make it accepted ?
Erik LaBianca
@easel
Is there an up-to-date version of the set plugin published somewhere? Scaladex lists the Resolver.bintrayRepo("veinhorn", "maven") at version 0.5.8 but I'm not getting anything.
Erik LaBianca
@easel
I went ahead and published the latest head to bintray. Resolver.bintrayRepo("7thsense", "maven") and resolvers += Resolver.bintrayRepo("7thsense", "sbt-plugins") with version 2322da3adcc7be79da5db8ca4ab5c566fb2659e9.
David Portabella
@dportabella

I've downloaded this example: https://github.com/kramer425/scala-js-chrome-extension-example
and modified this file: ./chrome-background-example/src/main/scala/Main.scala
with this very simple program:

import scala.scalajs.js.JSApp

object Main extends JSApp {
  def main(): Unit = {
    println(chrome.app.window.Window.getAll.length)
  }
}

When I install the extension, the background program fails with:

main.js:1151 Uncaught TypeError: Cannot read property 'onBoundsChanged' of undefined
    at $c_Lchrome_app_window_Window$.init___ (main.js:1151)
    at $m_Lchrome_app_window_Window$ (main.js:1178)
    at $c_LMain$.main__V (main.js:1687)
    at main.js:2990
    at main.js:2991

Any idea?

Alexis Hernandez
@AlexITC
@dportabella I don't know about such example but https://github.com/AlexITC/chrome-scalajs-template uses this library and works
Alexis Hernandez
@AlexITC
for anyone interested, I have forked the repo to get support for scalajs 1.0.0, it seems to work until now but I'm still testing: https://github.com/AlexITC/scala-js-chrome/tree/scalajs-1.0.0