Defeating the Apps Script 6 minute limit with gas-fakes

59 views
Skip to first unread message

Bruce Mcpherson

unread,
Jan 19, 2026, 9:50:18 AM (2 days ago) Jan 19
to Google Apps Script Community
How to bypass the 6-minute execution limit in Google Apps Script by running Apps Script code locally using Node.js gas-fakes. An example use case is provided, demonstrating how to find duplicate files in Google Drive, a process that often exceeds the Apps Script time limit.

Kildere S Irineu

unread,
Jan 19, 2026, 12:56:07 PM (2 days ago) Jan 19
to google-apps-sc...@googlegroups.com

 Passo a passo — Executando Apps Script localmente com gas-fakes

1️⃣ Instalar dependências

Crie uma pasta de projeto e rode:

mkdir gas-drive-duplicates cd gas-drive-duplicates npm init -y npm install gas-fakes googleapis @google-cloud/local-auth

2️⃣ Criar o arquivo .env

Adicione suas credenciais OAuth do Google Cloud:

GOOGLE_CLIENT_ID=SEU_CLIENT_ID GOOGLE_CLIENT_SECRET=SEU_CLIENT_SECRET GOOGLE_REDIRECT_URI=http://localhost GOOGLE_REFRESH_TOKEN=SEU_REFRESH_TOKEN

Essas credenciais são obtidas no Google Cloud Console, com a Google Drive API habilitada.


3️⃣ Criar o script findDuplicates.js

Aqui está um exemplo funcional completo que encontra arquivos duplicados no Google Drive, rodando fora do Apps Script:

// findDuplicates.js import 'dotenv/config'; import { google } from 'googleapis'; import { DriveApp } from 'gas-fakes'; // 🔹 Inicializa o cliente da API Drive com OAuth async function authorize() { const auth = new google.auth.OAuth2( process.env.GOOGLE_CLIENT_ID, process.env.GOOGLE_CLIENT_SECRET, process.env.GOOGLE_REDIRECT_URI ); auth.setCredentials({ refresh_token: process.env.GOOGLE_REFRESH_TOKEN }); return google.drive({ version: 'v3', auth }); } // 🔹 Simulação do DriveApp do GAS com gas-fakes async function findDuplicateFiles() { const drive = await authorize(); const fakeDrive = new DriveApp(drive); const filesMap = new Map(); let pageToken = null; do { const res = await drive.files.list({ fields: 'nextPageToken, files(id, name, md5Checksum)', pageSize: 1000, pageToken: pageToken || undefined, }); for (const file of res.data.files) { const key = file.md5Checksum || file.name; if (!key) continue; if (!filesMap.has(key)) filesMap.set(key, []); filesMap.get(key).push(file); } pageToken = res.data.nextPageToken; } while (pageToken); // 🔹 Identifica duplicados const duplicates = [...filesMap.values()].filter(arr => arr.length > 1); console.log(`🔍 ${duplicates.length} grupos de duplicados encontrados:`); for (const group of duplicates) { console.log(`\n📂 Arquivos duplicados: ${group[0].name}`); group.forEach(f => console.log(` - ${f.id}`)); } } findDuplicateFiles().catch(console.error);

🚀 Como funciona

  • O pacote gas-fakes recria objetos e métodos do Apps Script (DriveApp, SpreadsheetApp, etc.) localmente.

  • Você executa o script em Node.js, mas ele acessa as APIs reais do Google via googleapis.

  • Como está fora do ambiente Apps Script, não há limite de 6 minutos.

  • Você pode usar async/await, bibliotecas externas e armazenar progresso localmente (por exemplo, salvando checkpoints em JSON).


🧠 Boas práticas

  • Paginar resultados: sempre use pageToken ao listar arquivos grandes.

  • 💾 Salvar progresso: se estiver auditando dezenas de milhares de arquivos, salve checkpoints a cada lote processado.

  • 🔐 Segurança: mantenha suas credenciais no .env e nunca faça commit desse arquivo.

  • 🧱 Logs estruturados: use console.table() ou grave logs em CSV/JSON para auditar os resultados.


📘 Documentações úteis


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/google-apps-script-community/6abbfd59-5833-4e1d-a89e-170c2eadbe3fn%40googlegroups.com.

Jacob Edward

unread,
Jan 19, 2026, 7:32:50 PM (2 days ago) Jan 19
to google-apps-sc...@googlegroups.com
I was under the impression that if you deployed the stand alone web app and then used the UI it would be 6 minutes for every call so set it as a set timeout(caller,5*60*1000) where everything is in that caller() and then it pings back to the user

That's also true of the basic doGet() do post() for a REST like deployed custom API which then makes it possible to have the local node js be a JavaScript function in my single file .html 

That's important because node js isn't available on Android and I'm using Android as the developer device, desktop is backup 




Gemini told me there was a way to use GAS for Gemini calls

Can you tell me about when Gemini will be able to process proper single file HTML, it builds everything from scratch every time instead of making smaller updates iteratively to the same file

That should be default for end users, aka single click download from the main UI

This is the primary download link

This is the cloud folder if that file ever breaks

Version Control since May 21, 2023
Obviously kiwi is super important so I included the .apk 
Content files on drive gives the starter example
Political ramifications of tech
Lots of public dialogue with Grok

Jacob Edward Hoffer


--

DimuDesigns

unread,
10:24 AM (8 hours ago) 10:24 AM
to Google Apps Script Community
@Bruce Mcpherson

Like the idea of using the familiar mnemonics from GAS and applying them to different development environments.
Should make it easier for devs to transition to Cloud Run and Cloud Run Functions.
Reply all
Reply to author
Forward
0 new messages