glacambre / editor-adapter

A library to interact with in-browser JS editors like Ace, CodeMirror or Monaco
MIT License
5 stars 3 forks source link

Use wrappedJSObject and XPCNativeWrapper if available #4

Closed glacambre closed 3 years ago

glacambre commented 3 years ago

This commit makes editor-adapter use wrappedJSObject and XPCNativeWrapper if available. These two functions are Firefox-only APIs that enable manipulating the page's object from a webextension context without having to insert script tags in the page. This circumvents issues with websites where the CSP disallows injecting script tags.

This change is implemented by removing calls to executeInPage from editors and making their functions (getContent, setContent, getCursor...) context agnostics. The functions use a generic wrap and unwrap function which will correspond to wrappedJSObject and XPCNativeWrapper calls in firefox and will be polyfilled by the identity functions when executed in the page.

This change made the API very ugly, so convenience proxys and corresponding types that hide these changes were created.

Closes #3.