alexitc / chrome-scalajs-template Goto Github PK
View Code? Open in Web Editor NEWAn opinionated template for building browser extensions with scala-js
License: MIT License
An opinionated template for building browser extensions with scala-js
License: MIT License
I wanted to dabble a bit with browser storage and recalled that I have seen some template code for this. One search later, I arrived at:
def load(): Future[Option[Long]] = {
chrome.storage.Storage.local
// .get(key)
.get(???) // TODO: Fix
.map(_.asInstanceOf[js.Dictionary[String]])
.map { dict =>
val json = dict.getOrElse(StorageKey, "{}")
parse(json).toOption
.flatMap(_.as[Json].toOption)
.flatMap(_.hcursor.downField("lastUsedOn").as[Long].toOption)
}
}
I can't promise to take a crack at this, since using local storage would be, in my case, a bit of a workaround in itself, but I thought I'd ask you @AlexITC if you happened to have a working version. I certainly would not mind if it found its way into the template ;)
If I follow the steps in the Get Started I get an error like this one.
Upgrading sbt-scalajs-bundler
to 0.20.0
seems to solve it!
If I clone the project and run sbt test
I get:
[info] Fast optimizing /home/lcampos/Development/chrome-scalajs-template/target/scala-2.13/chrome-scalajs-template-test-fastopt
[info] Writing and bundling the test loader
[error] /home/lcampos/Development/chrome-scalajs-template/target/scala-2.13/scalajs-bundler/test/node_modules/webpack-cli/bin/cli.js:74
[error] throw err;
[error] ^
[error] Error: Cannot find module './scalajs.webpack.config'
[error] Require stack:
[error] - /home/lcampos/Development/chrome-scalajs-template/target/scala-2.13/scalajs-bundler/test/dev.webpack.config.js
[error] - /home/lcampos/Development/chrome-scalajs-template/target/scala-2.13/scalajs-bundler/test/node_modules/webpack-cli/bin/utils/convert-argv.js
[error] - /home/lcampos/Development/chrome-scalajs-template/target/scala-2.13/scalajs-bundler/test/node_modules/webpack-cli/bin/cli.js
[error] - /home/lcampos/Development/chrome-scalajs-template/target/scala-2.13/scalajs-bundler/test/node_modules/webpack/bin/webpack.js
[error] at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
[error] at Function.Module._load (internal/modules/cjs/loader.js:667:27)
[error] at Module.require (internal/modules/cjs/loader.js:887:19)
[error] at require (/home/lcampos/Development/chrome-scalajs-template/target/scala-2.13/scalajs-bundler/test/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
[error] at Object.<anonymous> (/home/lcampos/Development/chrome-scalajs-template/target/scala-2.13/scalajs-bundler/test/dev.webpack.config.js:3:18)
[error] at Module._compile (/home/lcampos/Development/chrome-scalajs-template/target/scala-2.13/scalajs-bundler/test/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
[error] at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
[error] at Module.load (internal/modules/cjs/loader.js:863:32)
[error] at Function.Module._load (internal/modules/cjs/loader.js:708:14)
[error] at Module.require (internal/modules/cjs/loader.js:887:19)
[error] at require (/home/lcampos/Development/chrome-scalajs-template/target/scala-2.13/scalajs-bundler/test/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
[error] at WEBPACK_OPTIONS (/home/lcampos/Development/chrome-scalajs-template/target/scala-2.13/scalajs-bundler/test/node_modules/webpack-cli/bin/utils/convert-argv.js:115:13)
[error] at requireConfig (/home/lcampos/Development/chrome-scalajs-template/target/scala-2.13/scalajs-bundler/test/node_modules/webpack-cli/bin/utils/convert-argv.js:117:6)
[error] at /home/lcampos/Development/chrome-scalajs-template/target/scala-2.13/scalajs-bundler/test/node_modules/webpack-cli/bin/utils/convert-argv.js:124:17
[error] at Array.forEach (<anonymous>)
[error] at module.exports (/home/lcampos/Development/chrome-scalajs-template/target/scala-2.13/scalajs-bundler/test/node_modules/webpack-cli/bin/utils/convert-argv.js:122:15)
[error] at /home/lcampos/Development/chrome-scalajs-template/target/scala-2.13/scalajs-bundler/test/node_modules/webpack-cli/bin/cli.js:71:45
[error] at Object.parse (/home/lcampos/Development/chrome-scalajs-template/target/scala-2.13/scalajs-bundler/test/node_modules/yargs/yargs.js:567:18)
[error] at /home/lcampos/Development/chrome-scalajs-template/target/scala-2.13/scalajs-bundler/test/node_modules/webpack-cli/bin/cli.js:49:8
[error] at Object.<anonymous> (/home/lcampos/Development/chrome-scalajs-template/target/scala-2.13/scalajs-bundler/test/node_modules/webpack-cli/bin/cli.js:375:3)
[error] at Module._compile (internal/modules/cjs/loader.js:999:30)
[error] at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
[error] at Module.load (internal/modules/cjs/loader.js:863:32)
[error] at Function.Module._load (internal/modules/cjs/loader.js:708:14)
[error] at Module.require (internal/modules/cjs/loader.js:887:19)
[error] at require (internal/modules/cjs/helpers.js:74:18)
[error] at Object.<anonymous> (/home/lcampos/Development/chrome-scalajs-template/target/scala-2.13/scalajs-bundler/test/node_modules/webpack/bin/webpack.js:80:2)
[error] at Module._compile (internal/modules/cjs/loader.js:999:30)
[error] at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
[error] at Module.load (internal/modules/cjs/loader.js:863:32) {
[error] code: 'MODULE_NOT_FOUND',
[error] requireStack: [
[error] '/home/lcampos/Development/chrome-scalajs-template/target/scala-2.13/scalajs-bundler/test/dev.webpack.config.js',
[error] '/home/lcampos/Development/chrome-scalajs-template/target/scala-2.13/scalajs-bundler/test/node_modules/webpack-cli/bin/utils/convert-argv.js',
[error] '/home/lcampos/Development/chrome-scalajs-template/target/scala-2.13/scalajs-bundler/test/node_modules/webpack-cli/bin/cli.js',
[error] Failure on parsing the output of webpack: No content to map due to end-of-input
[error] '/home/lcampos/Development/chrome-scalajs-template/target/scala-2.13/scalajs-bundler/test/node_modules/webpack/bin/webpack.js'
[error] at [Source: (ProcessPipeInputStream); line: 1, column: 0]
[error] ]
[error] }
[error] You can try to manually execute the command
[error] node /home/lcampos/Development/chrome-scalajs-template/target/scala-2.13/scalajs-bundler/test/node_modules/webpack/bin/webpack --bail --profile --json --mode development --config /home/lcampos/Development/chrome-scalajs-template/target/scala-2.13/scalajs-bundler/test/dev.webpack.config.js /home/lcampos/Development/chrome-scalajs-template/target/scala-2.13/scalajs-bundler/test/chrome-scalajs-template-test-fastopt-loader.js --output /home/lcampos/Development/chrome-scalajs-template/target/scala-2.13/scalajs-bundler/test/chrome-scalajs-template-test-fastopt-bundle.js
[error]
[error] stack trace is suppressed; run last Test / jsEnvInput for the full output
[error] (Test / jsEnvInput) Non-zero exit code: 1
[error] Total time: 202 s (03:22), completed 21/02/2021, 08:36:02
Manifest V3 for Chrome Extensions was introduced recently.
Currently the code only supports MV2.
I can tell a lot of work went into this and I doubt I would have had the patience to figure all of this out by myself from 0, so thanks!
There is a minor TODO note that has been in the project for a year now, it should be trivial to fix it: https://github.com/AlexITC/chrome-scalajs-template/blob/master/src/main/scala/com/alexitc/chromeapp/background/services/storage/StorageService.scala#L26
For any sane project, tests are mandatory, which gets a bit tricky in Scala.js browser extensions, let's add examples so that our users do not need to figure everything by themselves.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.