2

I'm trying the following code when i click on a button:

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;

But here's what the console says:

Uncaught TypeError: Cannot read property 'innerBounds' of null

And the debug of getAll() only returns my original window created in background.js. I don't get what i'm doing wrong...

Devz
  • 563
  • 7
  • 23

1 Answers1

3

chrome.app.window.create() is asynchronous.

By the time your execution reaches chrome.app.window.get('test'), that window does not exist yet.

You need to move your logic in the 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;
});
Community
  • 1
  • 1
Xan
  • 74,770
  • 16
  • 179
  • 206