happiness (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) happiness

久しぶりにchrome拡張開発したらmanifestがv3になってた

概要

1年半ぶりくらいに作るので、メモしておく

趣味プログラミング自体がめちゃくちゃ久しぶりだな...

manifest: scripts→service_worker

  "background": {
-     "scripts": ["background.js"],
-     "persistant": false
+    "service_worker": "background.js",
  },

manifest: page_action→action

- "page_action": {
+  "action": {

chrome.action

+ chrome.action.onClicked.addListener(action)
- chrome.pageAction.onClicked.addListener(action)
- chrome.extension.getURL('')
+ chrome.runtime.getURL('')

https://developer.chrome.com/docs/extensions/reference/runtime/#method-getURL

https://developer.chrome.com/docs/extensions/reference/extension/

error: Refused to load the stylesheet

Refused to load the stylesheet 'https://gist.github.com/rails/slides.css' because it violates the following Content Security Policy directive: "style-src 'unsafe-inline' github.githubassets.com". Note that 'style-src-elem' was not explicitly set, so 'style-src' is used as a fallback.

https://stackoverflow.com/questions/31211359/refused-to-load-the-script-because-it-violates-the-following-content-security-po

error

https://developer.chrome.com/docs/extensions/mv3/manifest/web_accessible_resources/#manifest-declaration

先頭に'/'ないとだめなようです。

融通きかんのう。

  "web_accessible_resources": [
    {
-      "resources": ["css/*"],
+      "resources": ["/css/*.css"],
      "matches": ["<all_urls>"]
    },

ログ

Denying load of <URL>. Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension.


Denying load of chrome-extension://aeijkdlcmbggbfhpkhhdefhcgmlhmpcd/js/init.js. Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension.

参考サイト

"Content-Security-Policy" について

https://qiita.com/goofmint/items/0b60dcc5eccad6c794a2

「HTTP」ってセキュリティ関係のこういうの無限にあるよね。

https://zenn.dev/wtetsu/articles/b92f579dcc8496

https://qiita.com/baby-0105/items/0356b0af4ab4585d86c4

で解けそうか...?(憶測)

やったね

これらを直したら動作の確認できたよ★

自分はgistをスライド化するscript書いてたけど、ほぼほぼ調査で時間費やしてしまった。

昨晩、overload 4見ながら、ビール850ml飲みつつ、スライドショーのライブラリの検索で、2時間くらい費やした。

その後、朝10時に起床し、動画見たりダラダラ音楽聞いたりご飯食べたりしつつ、tampermonkeyにて試そうとする。

しかし、使用しようとしたライブラリがCDNエラーになる。

お昼から親切な誰かがUPしてくれたchrome 拡張をパクる戦法に変更。

manifestがv2なのでv3に変更。

結論書いたコードは、30行もない。

"" + "" をヒアドキュメントに書き換えて行数稼ぎした程度。

トータルで、2 + 5 h 途中休憩 に4.5時間くらい = 約12.5h かかった。

感想

キャッチアップ面倒だと思いつつ、楽しんだ。

今まで制作したものを一気に変更できるようなscriptがほしいところだが、

後学のためというか、探すのがめんどくさくなってきたのでもそもそと変更加えた。

chrome拡張の開発は1年半振りというか思い出せる限りでは、2020年11,12月頃かもしれない。

そこからろくにプログラミング自体してないな。

そろそろ気持ち的には色々実装できるので、やってくかな...

腕治ったらとか言わずに...

まあまあやる気出た