read.js
1 import { cli, Strategy } from '@jackwener/opencli/registry'; 2 export const readCommand = cli({ 3 site: 'notion', 4 name: 'read', 5 description: 'Read the content of the currently open Notion page', 6 domain: 'localhost', 7 strategy: Strategy.UI, 8 browser: true, 9 args: [], 10 columns: ['Title', 'Content'], 11 func: async (page) => { 12 const result = await page.evaluate(` 13 (function() { 14 // Get the page title 15 const titleEl = document.querySelector('[data-block-id] [placeholder="Untitled"], .notion-page-block .notranslate, h1.notion-title, [class*="title"]'); 16 const title = titleEl ? (titleEl.textContent || '').trim() : document.title; 17 18 // Get the page content — Notion renders blocks in a frame 19 const frame = document.querySelector('.notion-page-content, [class*="page-content"], .layout-content, main'); 20 const content = frame ? (frame.innerText || frame.textContent || '').trim() : ''; 21 22 return { title, content }; 23 })() 24 `); 25 return [{ 26 Title: result.title || 'Untitled', 27 Content: result.content || '(empty page)', 28 }]; 29 }, 30 });