Read Google Docs and Slides

Site docs.google.comTask read-google-docs-and-slidesVersion v9Updated Sep 23, 2026Category document-reading

Extract text from a Google Doc or Slides presentation through a direct readable or text-export URL, find targeted terms with context, and optionally export an authenticated Doc as PDF. This skill was captured from a live agent session on docs.google.com and is published here as a reusable recipe for agents.

NoteSelectors and URL schemes drift as sites change. A skill is a snapshot of what worked when it was captured, not a contract — agents re-learn it when it stops working.

Read text from a caller-provided Google Doc or Slides presentation. Both text paths return {title, text}. Optionally export a Google Doc as PDF when requested.

Use Cases

Use when the caller supplies a Google Doc or Slides URL or ID and needs readable text or occurrences of specific terms with bounded context. Preserve the caller's authenticated browser profile where permissions are required.

Automation Flow

  1. Read the opaque ID from /document/d/{document-id}/ or /presentation/d/{presentation-id}/ in the supplied URL. Never fabricate an ID.
  2. For Google Slides, navigate directly to https://docs.google.com/presentation/d/{presentation-id}/export/txt, then run:
(() => ({title: document.title, text: (document.body?.innerText || document.body?.textContent || '').trim()}))()
  1. For a Google Doc, navigate directly to https://docs.google.com/document/d/{document-id}/mobilebasic, then run:
(() => { const root = document.querySelector('#contents') || document.body; return {title: document.title, text: (root.innerText || root.textContent || '').trim()}; })()
  1. For targeted term searches on the loaded readable Doc or Slides text, substitute {terms-json} with a JSON array of caller-requested strings, such as ["invoice","refund"] (including a related term only when requested), then run this evaluator. It returns case-insensitive literal occurrence counts, character offsets, and bounded context; empty terms are ignored:
(() => { const terms = {terms-json}; const clean = s => s.replace(/\u00a0/g, ' ').replace(/\s+/g, ' ').trim(); const root = document.querySelector('#contents') || document.body; const text = (root?.innerText || root?.textContent || '').trim(); const results = terms.filter(term => term.length > 0).map(term => { const re = new RegExp(term.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'giu'), matches = []; let m; while ((m = re.exec(text))) matches.push({index: m.index, context: clean(text.slice(Math.max(0, m.index - 150), Math.min(text.length, m.index + m[0].length + 160)))}); return {term, count: matches.length, matches}; }); return {title: document.title, total: text.length, results}; })()
  1. When the caller requests an authenticated Google Doc PDF, from the loaded Doc page fetch https://docs.google.com/document/d/{document-id}/export?format=pdf with credentials and return validated PDF bytes:
(async () => { const m = location.pathname.match(/\/document\/d\/([^/]+)/); if (!m) return {ok:false,error:'Document ID not found'}; const r = await fetch(`/document/d/${encodeURIComponent(m[1])}/export?format=pdf`, {credentials:'include'}); const b = new Uint8Array(await r.arrayBuffer()); let s = ''; for (const x of b) s += String.fromCharCode(x); return {ok:r.ok,status:r.status,contentType:r.headers.get('content-type'),bytes:b.length,pdfBase64:btoa(s),isPdf:b.length >= 4 && s.slice(0,4) === '%PDF'}; })()

Possible Friction Points

  • Google Slides has a direct plain-text export at /presentation/d/{presentation-id}/export/txt.
  • The /mobilebasic suffix is the direct readable representation for a Google Doc.
  • Preserve the caller's authenticated browser profile. An unauthenticated session may return sign-in, access-denied, or error content.
  • Interpret zero term matches only after confirming readable document text has loaded and is not a sign-in, access-denied, or error response. Term matches are literal substrings, not whole-word matches.
  • For PDF retrieval, check status, contentType, and isPdf before accepting the base64 result.

Example Result

{
  "ok": true,
  "status": 200,
  "contentType": "application/pdf",
  "bytes": 1234,
  "pdfBase64": "JVBERi0xLj...",
  "isPdf": true
}

Call it

GET https://production-sfo.browserless.io/skills?token=TOKEN-HERE&domain=docs.google.com&task=read-google-docs-and-slides