Reputation: 15488
I'm at the moment looking for a class or something that would make it possible to synchronously communicate with the Javascript of a tab.
It's a pain to dynamically manipulate a website with the default API. It would be so great if we could do something like this:
var tabs = require('sdk/tabs');
var exampleElement = tabs.activeTab.document.getElementById('exampleId');
console.log(exampleElement.innerHTML);
exampleElement.style.width = '200px';
So is there a class/lib that allows me to do this or can you tell me how I could make something like that possible? I'm really new to this...
Upvotes: 1
Views: 147
Reputation: 5830
One option would be to wrap async calls using the built-in promise library:
https://addons.mozilla.org/en-US/developers/docs/sdk/latest/modules/sdk/core/promise.html
This style of development is a little more obtuse than synchronous calls but it does avoid 'callback hell' when using multiple / nested callbacks.
Upvotes: 2
Reputation: 1393
As mentioned here, it's not possible with the addons SDK. You can use non-SDK code for synchronous communication, but if Firefox switches to a multi-process architecture, it will stop working. It's generally recommended to stick with the asynchronous APIs for new code.
Upvotes: 2