@@ -74,21 +74,23 @@ export function getCurrentTab() {
7474// https://stackoverflow.com/a/15292178/11898496
7575// https://stackoverflow.com/a/40815514/11898496
7676// https://stackoverflow.com/a/69507918/11898496
77- export async function setLocalStorage (
78- domain ,
79- key ,
80- value ,
81- willOpenActive = false
82- ) {
83- let tab = await chrome . tabs . create ( { active : willOpenActive , url : domain } ) ;
84- await chrome . scripting . executeScript ( {
85- target : { tabId : tab . id } ,
86- func : function ( _key , _value ) {
87- alert ( _key + " " + _value ) ;
88- localStorage . setItem ( _key , _value ) ;
89- } ,
90- args : [ key , value ] ,
77+ export function setLocalStorage ( domain , key , value , willOpenActive = false ) {
78+ return new Promise ( ( resolve , reject ) => {
79+ chrome . tabs . create ( { active : willOpenActive , url : domain } , ( tab ) => {
80+ chrome . scripting . executeScript (
81+ {
82+ target : { tabId : tab . id } ,
83+ func : function ( _key , _value ) {
84+ alert ( _key + " " + _value ) ;
85+ localStorage . setItem ( _key , _value ) ;
86+ } ,
87+ args : [ key , value ] ,
88+ } ,
89+ ( ) => {
90+ // !willOpenActive && chrome.tabs.remove(tab.id);
91+ resolve ( ) ;
92+ }
93+ ) ;
94+ } ) ;
9195 } ) ;
92-
93- ! willOpenActive && chrome . tabs . remove ( tab . id ) ;
9496}
0 commit comments