当我单击按钮时,我正在尝试以下代码:
chrome.app.window.create('sample.html', {
id: 'test',
'bounds': {
'width': 200,
'height': 200
},
'resizable' : false,
'frame': { type: "none" }
})
console.debug(chrome.app.window.getAll())
var windowcreated = chrome.app.window.get('test');
windowcreated.innerBounds.height = 50;
windowcreated.innerBounds.width = 200;
但是控制台是这样说的:
Uncaught TypeError: Cannot read property 'innerBounds' of null
并且 getAll() 的调试仅返回我在background.js 中创建的原始窗口。我不明白我做错了什么......
最佳答案
chrome.app.window.create()
是 asynchronous .
当您的执行到达 chrome.app.window.get('test')
时,该窗口尚不存在。
您需要将逻辑移至 callback of chrome.app.window.create
:
chrome.app.window.create('sample.html', {
id: 'test',
'bounds': {
'width': 200,
'height': 200
},
'resizable' : false,
'frame': { type: "none" }
}, function(createdWindow) {
// Do stuff here, and no need for get()
createdWindow.innerBounds.height = 50;
createdWindow.innerBounds.width = 200;
});
关于javascript - 无法使用 chrome.app.window.get 获取 chrome.window 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31073510/