Overriding Plugin

63 views
Skip to first unread message

Isaiah Inuwa

unread,
Aug 7, 2024, 5:33:26 PMAug 7
to FIDO Dev (fido-dev)
Does anyone have any tips on how to override WebAuthn APIs with a browser extension?

A simple test (outside of a browser extension) doesn't work for me:

```javascript
<head>
<script>
async function myWebAuthnCreate() {
  // ...
}
navigator.credentials.create = myWebAuthnCreate()
<script>
</head>
```

The native WebAuthn API still gets called in both Firefox and Chrome.

I took a look at what the [Bitwarden][] extension is doing, but trying to mimic what they're doing isn't working for me. I'm not familiar with browser extensions or JS API overrides in general, so I may be missing something simple.

For context, I'm trying to test a Linux WebAuthn platform API that I'm working on in the browser without having to patch in support for it.

Any help you can provide is appreciated.

Thanks!

Isaiah Inuwa

Joost van Dijk

unread,
Aug 8, 2024, 9:24:11 AMAug 8
to FIDO Dev (fido-dev), Isaiah Inuwa
I think what's missing is a correct manifest.json file.
This works for me:

{
  "manifest_version": 3,
  "name": "WebAuthn API override",
  "version": "1.0",
  "description": "sample",
  "content_scripts": [
    {
      "matches": ["<all_urls>"],
      "js": ["content.js"],
      "world": "MAIN",
      "run_at": "document_start"
    }
  ]
}

With the content.js script:

(function() {

  navigator.credentials.create = function(options) {
    return Promise.reject('navigator.credentials.create not implemented');
  };

  navigator.credentials.get = function(options) {
    return Promise.reject('navigator.credentials.get not implemented');
  };

})();

Isaiah Inuwa

unread,
Aug 8, 2024, 3:19:11 PMAug 8
to FIDO Dev (fido-dev), Joost van Dijk, Isaiah Inuwa
Ah, perfect! Works like a charm on both Firefox and Chrome (after updating Firefox to 128).

Thank you; you've saved me hours of hunting!

Cheers,
Isaiah Inuwa
Reply all
Reply to author
Forward
0 new messages