注意 現在は Manifest V3 が登場しているので、もしかしたら Manifest V3 とはやり方が異なるかもしれないが、備忘録として残しておく。Manifest V3 での方法については気が向いたらいずれ投稿する予定。 概要 Chrome 拡張機能の content_scripts のスクリプト内で XMLHttpRequest や fetch などの非同期通信を実行すると以下のようなエラーが発生する。 XMLHttpRequest cannot load https://example.com/. Origin chrome-extension://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx is not allowed by Access-Control-Allow-Origin このエラーは CORS というセキュリティ機能によるもので、許可されていな
![Chrome 拡張機能の content_scripts で CORS を回避する方法](https://cdn-ak-scissors.b.st-hatena.com/image/square/1b2c3d3f88fc3a5671a3a4e17ccd42711aaba0cc/height=288;version=1;width=512/https%3A%2F%2Fres.cloudinary.com%2Fzenn%2Fimage%2Fupload%2Fs--Bfgq7qcm--%2Fc_fit%252Cg_north_west%252Cl_text%3Anotosansjp-medium.otf_55%3AChrome%252520%2525E6%25258B%2525A1%2525E5%2525BC%2525B5%2525E6%2525A9%25259F%2525E8%252583%2525BD%2525E3%252581%2525AE%252520content_scripts%252520%2525E3%252581%2525A7%252520CORS%252520%2525E3%252582%252592%2525E5%25259B%25259E%2525E9%252581%2525BF%2525E3%252581%252599%2525E3%252582%25258B%2525E6%252596%2525B9%2525E6%2525B3%252595%252Cw_1010%252Cx_90%252Cy_100%2Fg_south_west%252Cl_text%3Anotosansjp-medium.otf_37%3AKosuke%252520Aoki%252Cx_203%252Cy_121%2Fg_south_west%252Ch_90%252Cl_fetch%3AaHR0cHM6Ly9saDMuZ29vZ2xldXNlcmNvbnRlbnQuY29tL2EtL0FPaDE0R2dtSnRsM0J6RVROZXhta2p1Rk9EYzRYbXZabVpqalVGX2tZVEdGPXM5Ni1j%252Cr_max%252Cw_90%252Cx_87%252Cy_95%2Fv1627283836%2Fdefault%2Fog-base-w1200-v2.png)