Creating a new chrome window in Manifest V3 - Error: Invalid type

1,050 views
Skip to first unread message

Tomakazu

unread,
May 3, 2022, 6:44:07 PM5/3/22
to Chromium Extensions
Working on converting manifest v2 to v3, I encountered this error when I create a new window as below (which works just fine in V2):

Error handling response: TypeError: Error in invocation of windows.create(optional object createData, optional function callback): Error at parameter 'createData': Error at property 'widtht': Invalid type: expected integer, found number.

Code: 
    chrome.windows.create({
            url: url,
            type: "normal",
            incognito: tab.incognito,
            width: defaultWidth,
            height: defaultHeight,
            left: defaultLeft,
            top: defaultTop,
            focused: false
        }, function (newwindow) {
            currWindowId = newwindow.id;
        });

my variable of "defaultWidth" is "number" indeed, but the createData as a parameter for "chrome.windows.create" should have "width" as "number" as well (as defined in this site: chrome.windows - Chrome Developers). 

How does v3 expects "width" as "integer"? Hope someone could help me out here. 

Thanks!


Cuyler Stuwe

unread,
May 3, 2022, 6:46:23 PM5/3/22
to Tomakazu, Chromium Extensions
An integer is a number without decimal points. Maybe you have a decimal here. Try Math.floor(...) or Math.round(...) and see whether that fixes it.

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/fd7c31df-1997-4251-a168-8bde7709c24dn%40chromium.org.

Masaki Itagaki

unread,
May 3, 2022, 7:00:16 PM5/3/22
to Cuyler Stuwe, Chromium Extensions
Thank you so much for your quick message, Cuyler. In fact, my defaultWidth comes from this initialization with Math.round. I just in case, also checked with floor but the same. Again, the code works just fine with Manifest v2...

width: Math.round(0.35 * chrome.windows.availWidth),

Cuyler Stuwe

unread,
May 3, 2022, 7:07:53 PM5/3/22
to Masaki Itagaki, Chromium Extensions
Does your code have the same typo in “width” that your original description has? 🤔

Masaki Itagaki

unread,
May 3, 2022, 7:19:13 PM5/3/22
to Cuyler Stuwe, Chromium Extensions
Yes. First, I create this object: 

  defaultDimensions: {
    state: 'normal',
    top: Math.round(chrome.windows.availTop),
    left: Math.round(chrome.windows.availLeft),  
    width: Math.round(0.35 * chrome.windows.availWidth),
    height: Math.round(1.0 * chrome.windows.availHeight)
},

defaultWidth = defaultDimentions.width;

Then call chrome.windows.create, passing "defaultWidth" as a part of the createData. I just apply Math.round again in the createData as below, but still complains with the same error. 

So, type wise, all are defined as "number", and Math.round should take care of the issue you pointed out, right? But asain, this is working fine under the manifest v2 :-(.

    chrome.windows.create({
            url: url,
            type: "normal",
            incognito: tab.incognito,
            width: Math.round(defaultWidth),
            ....

Cuyler Stuwe

unread,
May 3, 2022, 7:23:07 PM5/3/22
to Masaki Itagaki, Chromium Extensions
Hmm. I have an MV3 extension that’s successfully creating windows with predefined sizes, but it doesn’t have the same set of options you’re using here. Maybe some setting here is forcing a different code path where things are broken. 🤷‍♂️

Cuyler Stuwe

unread,
May 3, 2022, 7:25:43 PM5/3/22
to Masaki Itagaki, Chromium Extensions
Oh, uh… are you sure that chrome.windows.availWidth is actually something that exists?

Masaki Itagaki

unread,
May 3, 2022, 7:37:34 PM5/3/22
to Cuyler Stuwe, Chromium Extensions
Um, yeah, it should be since it works in V2 (adain the same code!). But I have not seriously looked into it. In case it's giving me some funky value, it should complain differently, right? But definitely worth looking into!

Cuyler Stuwe

unread,
May 3, 2022, 7:48:01 PM5/3/22
to Masaki Itagaki, Chromium Extensions
Yeah 0.35 * undefined is NaN, which isn’t an integer.

My guess is that if this existed in MV2, it might’ve been one of the things they got rid of from the Chrome API under the justification that there’s a standard Web API way to get it.

Simeon Vincent

unread,
May 3, 2022, 10:35:18 PM5/3/22
to Chromium Extensions, salem...@gmail.com, Chromium Extensions, Tomakazu
chrome.windows.availWidth sounds like the culprit to me. This property isn't in Chrome's API docs, the MDN API docs, in any extensions subdirectories in Chromium source, or in a quick check in DevTools I just ran. Perhaps you used chrome.windows.availWidth when you meant to use window.screen.availWidth (which isn't available in service workers)?

Take a look at chrome.system.display.getInfo() for getting display width info. You may also want to use the workArea property of the response object to account for users that have their taskbar/dock/etc. positioned on the side of their display.

Simeon - @dotproto
Chrome Extensions DevRel


To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.

Masaki Itagaki

unread,
May 3, 2022, 11:45:57 PM5/3/22
to Cuyler Stuwe, Chromium Extensions
Yeah, unfortunately that seems to be the story. So, it looks like I need to grab the max size of all directions (top. width, height, etc.) by temporarily maximizing the current window. What a pain...:-( Or there may be a better way, but I can't find any property in chrome.windows directly representing what I need there. But thanks for your time on this discussion. I leant one more thing still :-)

Masaki Itagaki

unread,
May 4, 2022, 12:42:51 AM5/4/22
to Simeon Vincent, Chromium Extensions, salem...@gmail.com
Thank you, Simon! It would be much more straightforward if I could use window.screen.... But looks like chrome.systeminfo has "Bounds" in which top, bottom, width and height are there. 
chrome.system.display - Google Chrome (3-72-0-dot-chrome-apps-doc.appspot.com)

But quickly calling like this gives another error: 

chrome.system.display.getInfo(function(displayInfo) { console.log("DEBUG: " + displayInfo); });


Uncaught TypeError: Cannot read properties of undefined (reading 'display')

I suppose chrome.system is NOT available in MV3, either...no? I'll look into it further. 


To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.

Masaki Itagaki

unread,
May 4, 2022, 2:04:54 AM5/4/22
to Simeon Vincent, Chromium Extensions, salem...@gmail.com
Found a solution for it. I needed to add "system.display" in the permission property in Manifest V3. Then the above error is gone. 

   "permissions": [ "system.display" ],

One is out. But I still get undefined for "bounds" in the displayInfo returned in the callback....still need to look into it. 

But thanks again Simon for your suggestion!!

wOxxOm

unread,
May 4, 2022, 10:08:21 AM5/4/22
to Chromium Extensions, Tomakazu, Chromium Extensions, salem...@gmail.com, Simeon Vincent
The returned value is an array so you should use displayInfo[0].bounds to access the `bounds` property. Also don't use `+` in console log as it doesn't work with arrays/objects: use `,` (a comma).

hrg...@gmail.com

unread,
May 4, 2022, 2:45:21 PM5/4/22
to Chromium Extensions, wOxxOm, Tomakazu, Chromium Extensions, salem...@gmail.com, Simeon Vincent
Keep in mind that system.display can return multiple monitors, so you have find which monitor the window belong to so you can obtain the correct workarea width.

Masaki Itagaki

unread,
May 4, 2022, 2:52:34 PM5/4/22
to hrg...@gmail.com, Chromium Extensions, wOxxOm, salem...@gmail.com, Simeon Vincent
Yes, I've already figured out displayInfo is an object array and display[0].bounds do have values for width, height, etc. But you're right in that it may be tricky if users have multiple displays. For my scenario, being definitive on the primary display is fine, but for some users, it may be a bit confusing. But anyway, my current issue can be resolved in using chrome.system.display.getInfo() -> displayInfo[0].bounds.width. 

Again, thank you all so much for jumping on this thread for help!!
Reply all
Reply to author
Forward
0 new messages