mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1587846 - [remote] Fix payload of return value for Page.captureScreenshot. r=remote-protocol-reviewers,ato
The actual screenshot data should be returned via the "data" property of an object. Also the data URL prefix has to be stripped off, so that only the base64 encoded data will be transmitted. Differential Revision: https://phabricator.services.mozilla.com/D52144 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
a7e1fdc48c
commit
605cf70003
@ -120,7 +120,12 @@ class Page extends Domain {
|
||||
// because it is no longer needed.
|
||||
snapshot.close();
|
||||
|
||||
return canvas.toDataURL();
|
||||
const url = canvas.toDataURL();
|
||||
|
||||
// only return the base64 encoded data without the data URL prefix
|
||||
const data = url.substring(url.indexOf(",") + 1);
|
||||
|
||||
return { data };
|
||||
}
|
||||
|
||||
async enable() {
|
||||
|
@ -9,26 +9,28 @@ async function getDevicePixelRatio() {
|
||||
});
|
||||
}
|
||||
|
||||
async function getImageDetails(client, image) {
|
||||
return ContentTask.spawn(gBrowser.selectedBrowser, image, async function(
|
||||
image
|
||||
) {
|
||||
let infoPromise = new Promise(resolve => {
|
||||
const img = new content.Image();
|
||||
img.addEventListener(
|
||||
"load",
|
||||
() => {
|
||||
resolve({
|
||||
width: img.width,
|
||||
height: img.height,
|
||||
});
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
img.src = image;
|
||||
});
|
||||
return infoPromise;
|
||||
});
|
||||
async function getImageDetails(format, data) {
|
||||
return ContentTask.spawn(
|
||||
gBrowser.selectedBrowser,
|
||||
{ format, data },
|
||||
async function({ format, data }) {
|
||||
return new Promise(resolve => {
|
||||
const img = new content.Image();
|
||||
img.addEventListener(
|
||||
"load",
|
||||
() => {
|
||||
resolve({
|
||||
width: img.width,
|
||||
height: img.height,
|
||||
});
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
|
||||
img.src = `data:image/${format};base64,${data}`;
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async function getViewportRect() {
|
||||
@ -42,33 +44,30 @@ async function getViewportRect() {
|
||||
});
|
||||
}
|
||||
|
||||
add_task(async function documentSmallerThanViewport(client) {
|
||||
add_task(async function documentSmallerThanViewport({ Page }) {
|
||||
loadURL(toDataURL("<div>Hello world"));
|
||||
|
||||
const { Page } = client;
|
||||
|
||||
info("Check that captureScreenshot() captures the viewport by default");
|
||||
const screenshot = await Page.captureScreenshot();
|
||||
const { data } = await Page.captureScreenshot();
|
||||
ok(!!data, "Screenshot data is not empty");
|
||||
|
||||
const scale = await getDevicePixelRatio();
|
||||
const viewportRect = await getViewportRect();
|
||||
const { width, height } = await getImageDetails(client, screenshot);
|
||||
|
||||
const { width, height } = await getImageDetails("png", data);
|
||||
is(width, (viewportRect.width - viewportRect.left) * scale);
|
||||
is(height, (viewportRect.height - viewportRect.top) * scale);
|
||||
});
|
||||
|
||||
add_task(async function documentLargerThanViewport(client) {
|
||||
add_task(async function documentLargerThanViewport({ Page }) {
|
||||
loadURL(toDataURL("<div style='margin: 100vh 100vw'>Hello world"));
|
||||
|
||||
const { Page } = client;
|
||||
|
||||
info("Check that captureScreenshot() captures the viewport by default");
|
||||
const screenshot = await Page.captureScreenshot();
|
||||
const { data } = await Page.captureScreenshot();
|
||||
ok(!!data, "Screenshot data is not empty");
|
||||
|
||||
const scale = await getDevicePixelRatio();
|
||||
const viewportRect = await getViewportRect();
|
||||
const { width, height } = await getImageDetails(client, screenshot);
|
||||
const { width, height } = await getImageDetails("png", data);
|
||||
|
||||
is(width, (viewportRect.width - viewportRect.left) * scale);
|
||||
is(height, (viewportRect.height - viewportRect.top) * scale);
|
||||
|
Loading…
Reference in New Issue
Block a user