Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions plugins/google-sheets-print-fix/BOOST.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: Sheets Print Fix
sites: docs.google.com
made: vandenng
preview: https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit
checks:
- on /spreadsheets/*: some of #docs-editor-container
- on /spreadsheets/*: none of .printing-canvas-container
---

When I press Cmd+P in Google Sheets, choose my formatting and press Next, print the formatted pages I chose, not a picture of what is on my screen.
9 changes: 9 additions & 0 deletions plugins/google-sheets-print-fix/listing.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "Sheets Print Fix",
"intent": "When I press Cmd+P in Google Sheets, choose my formatting and press Next, print the formatted pages I chose, not a picture of what is on my screen.",
"host": "docs.google.com",
"by": "vandenng",
"picks": false,
"preview": "https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit",
"added": "2026-11-24"
}
14 changes: 14 additions & 0 deletions plugins/google-sheets-print-fix/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"manifest_version": 3,
"name": "Sheets Print Fix",
"version": "1.0.0",
"description": "Google Sheets' Print (Cmd+P, then Next) prints the formatted pages you chose instead of a picture of the screen.",
"content_scripts": [
{
"matches": ["https://docs.google.com/*"],
"css": ["page/style.css"],
"js": ["page/page.js"],
"run_at": "document_end"
}
]
}
65 changes: 65 additions & 0 deletions plugins/google-sheets-print-fix/page/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Google Sheets print fix for Yab.
// Sheets appends <style class="offline-printing-css"> and <div class="printing-canvas-container">
// to <body> when printing starts, and removes both as soon as window.print() returns.
// Yab renders the page for printing a moment later, so the formatted pages are gone by then.
// This puts Sheets' own nodes back until the print is over. Nothing is read, sent or stored.
(() => {
if (!location.pathname.startsWith('/spreadsheets/')) return

const KEEP_MS = 5 * 60 * 1000
let held = null // { style, cont } that we put back
let pending = {} // nodes Sheets just added for the current print
let printed = false // Yab's real print pass has finished since we put them back
let timer = 0

const drop = () => {
clearTimeout(timer)
if (!held) return
held.cont.remove()
held.style.remove()
held = null
}

const observer = new MutationObserver((records) => {
for (const record of records) {
for (const node of record.addedNodes) {
if (node.nodeType !== 1) continue
if (held && (node === held.cont || node === held.style)) continue
if (node.classList.contains('printing-canvas-container')) {
drop() // a new print replaces the last one
pending.cont = node
} else if (node.tagName === 'STYLE' && node.classList.contains('offline-printing-css')) {
pending.style = node
}
}
}
// Sheets has taken its pages away again: put them back for the real print pass.
if (pending.cont && pending.style && !pending.cont.isConnected && !pending.style.isConnected) {
held = pending
pending = {}
printed = false
document.body.append(held.style, held.cont)
clearTimeout(timer)
timer = setTimeout(drop, KEEP_MS)
}
})
observer.observe(document.body, { childList: true })

const onAfterPrint = () => { if (held) printed = true }
// The print dialog covers the window, so the first click or key on the page means it is closed.
const onInput = () => { if (held && printed) drop() }

window.addEventListener('afterprint', onAfterPrint)
document.addEventListener('pointerdown', onInput, true)
document.addEventListener('keydown', onInput, true)

const cleanup = () => {
observer.disconnect()
window.removeEventListener('afterprint', onAfterPrint)
document.removeEventListener('pointerdown', onInput, true)
document.removeEventListener('keydown', onInput, true)
drop()
}
if (typeof boost !== 'undefined' && boost.cleanup) boost.cleanup(cleanup)
return cleanup
})()
9 changes: 9 additions & 0 deletions plugins/google-sheets-print-fix/page/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@media screen {
.printing-canvas-container {
position: fixed !important;
left: -20000px !important;
top: 0 !important;
visibility: hidden !important;
pointer-events: none !important;
}
}
41 changes: 41 additions & 0 deletions scripts/trials/google-sheets-print-fix.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Printing itself cannot be driven here, so the trial plays Sheets' part:
// when a print starts, Sheets appends <style class="offline-printing-css"> and
// <div class="printing-canvas-container"> to <body>, and removes both as soon
// as window.print() returns. Yab renders the print a moment later, so the
// plugin must put the same two nodes back, keep them off the screen, and take
// them away again once the print is over and the person touches the page.
export default {
async act(page, { sleep }) { await sleep(1500); },
async expect(page, { sleep }) {
await page.evaluate(() => {
const style = document.createElement('style');
style.className = 'offline-printing-css';
const pages = document.createElement('div');
pages.className = 'printing-canvas-container';
pages.append(document.createElement('canvas'));
document.body.append(style, pages);
window.__trial = { style, pages };
});
await sleep(200);
await page.evaluate(() => { window.__trial.pages.remove(); window.__trial.style.remove(); });
await sleep(400);
const back = await page.evaluate(() => {
const { style, pages } = window.__trial;
return { style: style.isConnected, pages: pages.isConnected, hidden: getComputedStyle(pages).visibility === 'hidden' };
});
// A click before the print pass has finished must not take the pages away.
await page.mouse.click(5, 5);
await sleep(200);
const early = await page.evaluate(() => window.__trial.pages.isConnected);
await page.evaluate(() => window.dispatchEvent(new Event('afterprint')));
await page.mouse.click(5, 5);
await sleep(300);
const after = await page.evaluate(() => window.__trial.pages.isConnected || window.__trial.style.isConnected);
const problems = [];
if (!back.style || !back.pages) problems.push(`not put back (style ${back.style}, pages ${back.pages})`);
if (!back.hidden) problems.push('the held pages show on screen');
if (!early) problems.push('a click before the print finished removed the pages');
if (after) problems.push('the pages stayed after the print and a click');
return problems.length ? { ok: false, detail: problems.join('; ') } : { ok: true, detail: 'print pages put back after Sheets removed them, hidden on screen, removed after the print' };
},
};
Loading