Search code examples
javascriptgoogle-chromecryptography

How to use SubtleCrypto in chrome (window.crypto.subtle is undefined)


This is really embarassing

on virtually any site on the internet,

window.crypto.subtle

returns

SubtleCrypto {}
  __proto__: SubtleCrypto

in the chrome console (v61 (Official Build) (64-bit))

except for

my webpage, and blank.org

where

window.crypto.subtle

returns

undefined

according to https://developer.mozilla.org/en-US/docs/Web/API/Crypto/subtle it's a read-only property that should always return a SubtleCrypto object.

what could I have done, or what has blank.org done that it could possibly not?

ps: in firefox it seems to work as intended on both my site and blank.org


Solution

  • According to the spec (via Github issues) a la this Google page for WebCrypto:

    crypto.subtle is supposed to be undefined in insecure contexts