tmegos blog

Web developer

Google Cloud Messaging(GCM)はCross-Origin Resource Sharing(CORS)に対応してないらしい

Web Pushが動くデモサイトをhtmlとJavaScriptのみで作っていたら、Push時に以下のようなエラーになった。

Fetch API cannot load https://gcm-http.googleapis.com/gcm. Response to
preflight request doesn't pass access control check: No
'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://localhost' is therefore not allowed access. The
response had HTTP status code 405. If an opaque response serves your
needs, set the request's mode to 'no-cors' to fetch the resource with
CORS disabled.

どうやらGCMはクロスドメインに対応していないらしい。
PushはJavaScriptではなく別の仕組みを使わないといけないですね。

蛇足

FirefoxのWeb Pushサーバだとクロスドメインでも動く。

2016/03/06追記

Firefoxもクロスドメイン非対応になっていた。