Pass large blob or file from chrome extension

前端 未结 2 1642
南笙
南笙 2020-12-20 19:48

I try to write an extension caching some large media files used on my website so you can locally cache those files when the extension is installed:

  1. I pass the
2条回答
  •  独厮守ぢ
    2020-12-20 20:28

    Two possibilities I can think of.

    1) Employ externally_connectable.

    This method is described in the docs here.

    The essence of it: you can declare that such and such webpage can pass messages to your extension, and then chrome.runtime.connect and chrome.runtime.sendMessage will be exposed to the webpage.

    You can then probably make the webpage open a port to your extension and use it for data. Note that only the webpage can initiate the connection.

    2) Use window.PostMessage.

    The method is mentioned in the docs (note the obsolete mention of window.webkitPostMessage) and described in more detail here.

    You can, as far as I can tell from documentation of the method (from various places), pass any object with it, including blobs.

提交回复
热议问题