Purpose
Read the text contents of an identified Google Doc or Google Slides presentation using the caller's authenticated Browserless browser profile, without relying on the interactive editor shell. Optionally retrieve an authenticated PDF representation for a Google Doc.
When to Use
Use when the caller supplies a standard Google Docs or Google Slides URL, document/presentation ID, or an identified file accessible through the configured Browserless profile. The session must retain the caller's authentication and permissions.
Workflow
- Determine the resource type and opaque ID from the supplied URL. A Doc ID is the segment in
/document/d/{document-id}/; a Slides presentation ID is the segment in/presentation/d/{presentation-id}/. Do not guess an ID. - For a Google Slides presentation, construct and navigate directly to
https://docs.google.com/presentation/d/{presentation-id}/export/txt. This export endpoint returns the presentation's slide text and avoids the interactive Slides application. - On the loaded Slides export page, run this evaluator:
(() => {
const text = (document.body?.innerText || document.body?.textContent || '').trim();
return { title: document.title, text };
})()- For a Google Doc, navigate directly to
https://docs.google.com/document/d/{document-id}/mobilebasicinstead of the/editapplication shell. For visible text, run:
(() => {
const root = document.querySelector('#contents') || document.body;
return {
title: document.title,
text: (root.innerText || root.textContent || '').trim()
};
})()- For a Google Doc PDF download, use
https://docs.google.com/document/d/{document-id}/export?format=pdf. From the loaded mobile-basic page, run this evaluator and returnpdfBase64to the caller for local PDF decoding:
(async () => {
const match = location.pathname.match(/\/document\/d\/([^/]+)/);
if (!match) return {ok: false, error: 'Document ID not found in current URL'};
const documentId = match[1];
const response = await fetch(`/document/d/${encodeURIComponent(documentId)}/export?format=pdf`, {
credentials: 'include'
});
const bytes = new Uint8Array(await response.arrayBuffer());
let binary = '';
for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
return {
ok: response.ok,
status: response.status,
contentType: response.headers.get('content-type'),
bytes: bytes.length,
pdfBase64: btoa(binary),
isPdf: bytes.length >= 4 && String.fromCharCode(bytes[0], bytes[1], bytes[2], bytes[3]) === '%PDF'
};
})()Site-Specific Gotchas
- Google Slides has a direct plain-text export at
/presentation/d/{presentation-id}/export/txt; use it as the first and usually only navigation for text extraction. - The Slides text export may render as a plain body rather than a structured document, so extract
document.body.innerTextwith a text-content fallback. - The
/mobilebasicsuffix is the direct readable representation for a Google Doc and avoids relying on the interactive Docs editor UI. - The PDF endpoint is the document's
/export?format=pdfURL, not the/mobilebasicURL; retain the authenticated browser session when fetching it. - Preserve the caller's Browserless profile/session, such as
mcps-matthew; an unauthenticated session may show sign-in, access-denied, or error content instead of the file. - Document and presentation IDs are opaque URL segments. Read them from the supplied URL and never fabricate them.
- Check extracted text for access or authentication error messages before treating it as the requested content.
- Check
status,contentType, andisPdfbefore treating returned PDF base64 as a valid PDF.
Expected Output
For reading a Google Doc or Slides presentation, return:
{"title":"<page title>","text":"<visible document or presentation text>"}For PDF retrieval, return:
{"ok":true,"status":200,"contentType":"application/pdf","bytes":12345,"pdfBase64":"<base64 PDF>","isPdf":true}The text may include UI, authentication, or access-error messaging if the configured session cannot access the resource. The PDF response may similarly contain an error page rather than a PDF when access is unavailable.