Loading a file within the extension

Is it possible to load a text file from within the addon? I don’t mean on the user’s system, of course, but a file included in the extension itself.

My plan is to use a text file as a resource, possibly to generate some CSS from it.

Thanks

I have a solution, though I would like to know whether there is a more built-in method.

Basically, I use a combination of Ajax and chrome.extension.getURL.

Of course, that means yet another callback, but all in a day’s work …

I don’t think this is possible. But you can use storage.local to save your css styles, and you can retrieve them back when you need. Use chrome.storage.local.set and chrome.storage.local.get , you can save as many “files” as you need in the local. But maybe there are some limits, this is not clearly stated in Mozilla docs.

I was able to get the job using ajax, as above. It’s painful getting the timing right with the callback, but it works well enough otherwise.

Pity about there not being a better method. At least I know not to waste my time looking.

Thanks

Well, there is at least one way to load files synchronously:

You can wrap the file as a string in a .js file and include that with a synchronous <script> tag.