I am developing a Firefox extension.
And I have injected some js into web page in extension. These js will execute and transfer data to extension.
For example, I inject
function example(srcElement, action) {
var event = document.createEvent('Events');
event.initEvent('example', true, true);
var o = {};
o.actionName = action;
srcElement.setUserData('exampleData', o, null);
srcElement.dispatchEvent(event);
}
Meanwhile I add a listener of extension side to the document.
Then if function example executes, extension listener will be called and get data and the srcElement.
Question is : Now setUserData is deprecated and there is no method to transfer data and element.
The replacement of setUserData is
Element.dataset
This API can only transfer string.
Then I tried
window.postMessage
This API can transfer array and object but not element.
So how can I transfer element and data both?