I was facing the same problem so I implemented script that will inject file with this code:
[window.screen.availWidth, window.screen.availHeight - (Math.max(window.outerHeight - window.innerHeight, 0) || 78)];
into one tab in every opened window:
async function extractResolutions() {
const windows = await browser.windows.getAll({populate: true, windowTypes: [browser.windows.WindowType.NORMAL]});
const tabs = flatten(windows.map(win => win.tabs.find(tab => !tab.discarded && tab.url.startsWith('http')))).filter(x => x);
return await Promise.all(tabs.map(tab => browser.tabs.executeScript(tab.id, {allFrames: false, file: 'cs_screen_size.js', runAt: 'document_start'}).then(([x]) => x).catch(() => false)).filter(x => x));
}
const flatten = arrayOfArrays => Array.prototype.concat.apply([], arrayOfArrays);
Note that:
-
browser.tabs.executeScript
returns value of last statement in your content script (in this case array [width, height]
- only NORMAL windows and http(s) pages are used, because you cannot inject script into pages like about:
- you may need to tweak the script - there is a magic number 78 that should represent default browser toolbar size
- it returns array of tuples, for example: [[1920, 1079], [2560, 1319]]