Utilizing both the selection API and clipboard API, I have implemented a feature in my addon where data selected by the user is copied to the clipboard directly when a button is clicked (triggering the handleClick function). However, an issue arises when attempting to stop the addon by clicking back on the button, resulting in an error message stating that data should be string
.
var self = require('sdk/self');
var clipboard = require("sdk/clipboard");
var selection = require("sdk/selection");
var selected_text =[];
var result;
var flag = false ;
function myListener() {
if (selection.text){
selected_text= selected_text.concat(selection.text);
result= selected_text.toString();
}
clipboard.set(result);
}
function handleClick(state) {
if (!flag){
selection.on('select', myListener);
flag= true;
} else {
clipboard.set(null);
}
}
require("sdk/ui/button/action").ActionButton({
id: "Selection",
label: "Click to start saving your next selections to clipboard",
icon: {
"16": "./icon-16.png",
"32": "./icon-32.png",
"64": "./icon-64.png"
},
onClick: handleClick
});
Exact error Msg :
JPM undefined Message: RequirementError: The option "data" must be one of the following types: string
If anyone could provide guidance on how to successfully stop and start the addon with a button click and identify where the error is occurring, it would be greatly appreciated.