Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /html/canvas/mozPrintCallback-global-print.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="match" href="mozPrintCallback-rect-001-print-ref.html">
<style>
canvas {
background: yellow;
}
</style>
<canvas id="myCanvas" width="80" height="80"></canvas>
<script>
function getGlobal(obj) {
return Object.getPrototypeOf(obj).constructor.constructor("return globalThis")();
}
let myCanvas = document.getElementById("myCanvas");
myCanvas.mozPrintCallback = function (obj) {
let ctx = obj.context;
let globalMatches = getGlobal(ctx) == getGlobal(myCanvas) &&
getGlobal(obj) == getGlobal(myCanvas);
ctx.fillStyle = globalMatches ? "cyan" : "red";
ctx.fillRect(0, 0, 60, 60);
obj.done();
}
</script>