Я хочу, чтобы окно подсказывало пользователю, когда оно создается впервые. Мой код запрашивает пользователя, создает ли он ДРУГОЕ новое окно (например: вынимает вкладку из окна, чтобы создать свое собственное окно, или щелкает значок chrome во второй раз), но не при создании самого ПЕРВОГО окна. , Почему это так?
Фоновый скрипт:
//an array of current open windows.
var windowArray = {};
//when a new window is created, start the creation of a new package.
chrome.windows.onCreated.addListener(createWindowPackage);
//get current window's id
function getCurrentWinID(callback){
console.log("getCurrentWinID() called")
var windId;
chrome.windows.getCurrent(function(currentWin){
windId = currentWin.id;
//console.log("from getCurrentWinID(), windId = " + windId)
//*****unique window Id properly getting retrieved here
callback(windId);
});
}
//_______________________________________________________________________________________
//start the creation of a new 'windowPackage' object by prompting the user for a goal.
function createWindowPackage(){
var goal = prompt("What is your goal this browsing session?","E.g: To watch Daniel Schiffman's first video.");
var windId;
//getting the current window's id
getCurrentWinID(function(windId){
var winId = windId.toString();
//*****unique window id properly received here
//in the windowArray, have the windId key refer to a new windowPackage object.
windowArray[winId] = new windowPackage(goal, windId);
//*****so we've successfully created a new window package with this goal and a unique window Id
});
}
//_________________________________________________________________________________________
//a window package includes the window id and a tasks[] array
class windowPackage{
constructor(startTask, winId){
this.id = winId;//winId is a string right now.
this.tasks = [startTask];
this.goal = startTask;
this.isItOn = 1;
}
Каким-то образом приведенный выше код не работает для запроса пользователя при создании первого нового окна, но этот код работает:
//an array of current open windows.
var goal;
chrome.windows.onCreated.addListener(askGoal);
function askGoal(){
goal = prompt("What is your goal this browsing session?","E.g: To watch Daniel Schiffman's first video.");
isItOn = 1;
}