October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
Mountain View desk3 min

Playwright screenshot को Google Drive में automatically save कैसे करें

Playwright से PNG screenshot लेकर Google Drive API v3 में सीधे upload करें—buffer या file stream के साथ, और सही OAuth identity व folder access चुनकर।
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Playwright से screenshot लेकर उसे Google Drive में अपने-आप रखने का सबसे सीधा तरीका है: page.screenshot() से PNG bytes लें और Google Drive API v3 के files.create अनुरोध में उन्हें media के रूप में upload करें। इससे temporary file की जरूरत नहीं पड़ती। अगर file को disk पर भी रखना है, तो screenshot path पर लिखें और fs.createReadStream() से upload करें।

काम करने वाला flow क्या है?

हर run में ये तीन काम होंगे: Playwright पेज खोलकर screenshot बनाएगा, Drive API authenticated identity के जरिए file बनाएगी, और आप चाहें तो Drive folder ID देकर उसे चुने हुए folder में रखेंगे। PNG screenshot के साथ image/png MIME type इस्तेमाल करें। नीचे का तरीका buffer को सीधे upload करता है, इसलिए runner में relative file path की समस्या भी नहीं आती।

  1. Google Cloud project में Google Drive API enable करें और अपने runtime के लिए authentication credentials तैयार करें।
  2. Node.js project में playwright, googleapis और google-auth-library install करें।
  3. Drive API client को सही auth identity के साथ configure करें।
  4. Playwright से screenshot buffer लें और उसे files.create के media body में भेजें।

Google की Drive API create-file guide file metadata और content बनाने का तरीका बताती है; upload guide media upload के विकल्प समझाती है।

Node.js में screenshot को सीधे Drive पर upload करें

उदाहरण में Playwright Chromium launch करता है, पेज खोलता है, full-page PNG buffer लेता है, फिर Drive में नई file बनाता है। इसे save-screenshot.js में रखें। यह मानता है कि auth पहले से आपके execution environment के अनुसार configure किया गया है; authentication के विकल्प अगले section में दिए हैं।

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Vansuny 128GB USB C Flash Drive 2 in 1 OTG USB 3.0 + Type C Memory Stick with Keychain Dual Type C Thumb Drive Photo Stick Jump Drive for Android Smartphones, Computer, Tablet, PC
  • 【Important】: Default format of the usb flash drive 128gb is exFAT as this is the format recognized by the smartphones and tablets. These 128gb thumb drives are only compatible with C-Port enabled mobile phones & computers only. While formatting the usb flash drive dual type c usb 3.0 OTG keep a check on the drive format
  • 【Easy to Use】: Directly plug the 2-in-1 USB flash drive and play, no need to install any software. The jump drive is easy to be recognized by computer, laptop, notebook, PC, car audio, speaker, smart TV, vidoe projector etc
  • 【Fast Speed】: High-speed USB 3.0 flash drive for fast data transfer, backwards compatible with USB 2.0 easy to complete the storage and transport functions. USB 3.0 and Class A chip help you transfer a 4G movie from the thumb drive to your smartphone in about 40 seconds, and reverse transfer in 2 mins to save memory for your smartphone with Type C port.Save your time
  • 【Good Compatibility】: Dual connectors USB type C + USB 3.0. Support windows 7 / 8 / 10 / XP / 2000 / ME / NT Linux and Mac OS, compatible withUSB 3.0 & USB 2.0 backwards USB1.1. Support videos formats: AVI, M4V, MKV, MOV, M P4, MPG, RM, RMVB, TS, WMV, FLV, 3GP; AUDIOS: FLAC, APE, AAC, AIF, M4A, MP3, WAV
  • 【OTG Function】:Support nearly all mobile phones which support OTG function,and very easy to operate
const { chromium } = require('playwright');
const { google } = require('googleapis');

async function main() {
  // Configure auth for your runtime before creating the Drive client.
  const auth = /* configured Google auth client */;
  const drive = google.drive({ version: 'v3', auth });
  const browser = await chromium.launch({ headless: true });

  try {
    const page = await browser.newPage();
    await page.goto('https://example.com', { waitUntil: 'networkidle' });

    const png = await page.screenshot({ fullPage: true, type: 'png' });
    const runId = new Date().toISOString().replace(/[:.]/g, '-');

    const result = await drive.files.create({
      requestBody: {
        name: `example-${runId}.png`,
        mimeType: 'image/png',
        // Optional: set a Drive folder ID the authenticated identity can access.
        // parents: ['YOUR_DRIVE_FOLDER_ID'],
      },
      media: {
        mimeType: 'image/png',
        body: png,
      },
      fields: 'id, name, webViewLink',
    });

    console.log(result.data);
  } finally {
    await browser.close();
  }
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

page.screenshot() path न देने पर image bytes लौटाता है, जिन्हें यहां सीधे media body में दिया गया है। Playwright screenshot के उपलब्ध व्यवहार के लिए Screenshots documentation और Page API देखें। Google client का upload उदाहरण readable stream इस्तेमाल करता है; buffer को सीधे media के रूप में देने के बजाय आप नीचे का disk-file विकल्प अपना सकते हैं।

Disk पर screenshot रखना हो तो

यह विकल्प तब उपयोगी है जब CI artifact, local debugging या upload retry के लिए screenshot की स्थानीय copy भी चाहिए। Drive API के media.body को readable stream दें:

const fs = require('node:fs');
const path = require('node:path');

const screenshotPath = path.resolve('artifacts/page.png');
await fs.promises.mkdir(path.dirname(screenshotPath), { recursive: true });
await page.screenshot({ path: screenshotPath, fullPage: true, type: 'png' });

const result = await drive.files.create({
  requestBody: {
    name: 'page.png',
    mimeType: 'image/png',
    // parents: ['YOUR_DRIVE_FOLDER_ID'],
  },
  media: {
    mimeType: 'image/png',
    body: fs.createReadStream(screenshotPath),
  },
  fields: 'id, name, webViewLink',
});

Relative screenshot paths process की current working directory के सापेक्ष resolve होते हैं। CI में absolute path या स्पष्ट artifact directory चुनें, और सुनिश्चित करें कि screenshot capture पूरा होने के बाद ही stream बनाई जाए। यदि स्थानीय copy की जरूरत नहीं, buffer तरीका temporary-file handling हटाता है।

Google Drive authentication और file ownership चुनें

सिर्फ API call लिखना पर्याप्त नहीं: token किस identity का है, यह तय करता है कि file कहां बनेगी और कौन उसे देख पाएगा। Google का Node.js quickstart API enable करने और local browser-based OAuth setup का उदाहरण देता है। Quickstart testing के लिए simplified है; उसका browser flow remote terminal या हर unattended production runner के लिए ज्यों का त्यों उपयुक्त नहीं मानना चाहिए।

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Local development में user OAuth

जब developer अपने खाते से login करके परीक्षण करता है, OAuth user की identity में Drive operation होता है और बनाई file उस user की Drive में रहती है। Google quickstart में दिखाया गया read-only metadata scope केवल सूची पढ़ने जैसे demo के लिए है; upload के लिए उसे copy न करें। अपने उपयोग के लिए न्यूनतम आवश्यक Drive write scope चुनें।

Unattended CI या server में identity

CI runner में browser prompt पर निर्भर flow के बजाय संगठन की नीति और file ownership जरूरत के अनुरूप server-side credentials या delegated user flow चुनें। Service account से बनाई file service account की ownership में होती है और वह किसी कर्मचारी के My Drive में अपने-आप नहीं दिखाई देती। यदि destination shared location या user-visible folder है, तो access और sharing व्यवस्था पहले सत्यापित करें। हर Google Workspace संगठन की policy अलग हो सकती है।

Rank #3
Sale
SANDISK 128GB Ultra Dual Drive, USB-C & USB-A, Up to 150MB/s Read Speeds
  • Easily transfer files between smartphones, tablets and computers
  • Free up space on your Android smartphone (Mobile device requires USB Type-C port and On-The-Go (OTG) support)
  • Retractable design with a reversible USB Type-C connector and a traditional USB connector
  • High-speed USB 3.1 performance of up to 150MB/s Read Speeds (USB Type-C port with USB 3.1, Gen. 1/USB 3.0 support required. Based on internal testing; performance may be lower depending upon host device.)
  • SanDisk Memory Zone app for Android (available on Google Play; Download and installation required) lets you easily manage and back up content on your smartphone and tablet

Destination folder

requestBody.parents में folder ID दें; authenticated identity को उस folder तक access होना चाहिए। Response के id और webViewLink को log या अपने job result में रखें, ताकि upload के बाद file ढूंढना आसान हो। Drive API में metadata और media एक request में भेजे जा सकते हैं।

Format, नाम और capture व्यवहार

  • PNG: type: 'png', file extension .png और MIME type image/png को एकसाथ रखें।
  • पूरी page: fullPage: true लंबवत scrollable page को capture करता है; बड़े पेज पर image काफी लंबी हो सकती है।
  • हर run का नाम: timestamp, test name या run identifier जोड़ें। अलग नाम नई file बनाते हैं; files.create को उसी नाम से चलाने पर पुरानी file स्वतः overwrite होने की धारणा न रखें।
  • पेज readiness: जरूरत के हिसाब से page.goto() का wait condition चुनें। यदि पेज dynamic content बाद में दिखाता है, तो capture से पहले आवश्यक selector के दिखाई देने का इंतजार करें।

Upload की लागत, समय और reliability

Screenshot लेना और Drive upload करना अलग चरण हैं। Full-page capture में पेज की लंबाई और rendering का असर हो सकता है; upload में network और Google API response का। बड़े batch में हर page के लिए नया browser launch करने के बजाय browser lifecycle को job के अनुरूप रखें, और failures को capture तथा upload चरण के हिसाब से log करें।

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

यदि upload fail हो, तो capture buffer या local file को अस्थायी रूप से सुरक्षित रखने से दोबारा upload करना संभव होगा। Retry policy बनाते समय duplicate files का ध्यान रखें: retry में नया filename न बनाया जाए, या अपने job record में सफल Drive file ID रखा जाए। यह उपयोगकर्ता द्वारा चुनी गई retry व्यवस्था है, Drive द्वारा स्वचालित overwrite नहीं।

आम समस्याएं और समाधान

  • 403 या authorization error: Drive API enabled है या नहीं, token में upload-योग्य scope है या नहीं, और चुनी हुई identity को destination folder का access है या नहीं जांचें।
  • Upload सफल है लेकिन file नहीं मिलती: files.create response का ID देखें और जांचें कि credentials किस Google identity के हैं। Service-account-owned file किसी user की Drive में स्वतः नहीं आती।
  • File खाली या खुल नहीं रही: await page.screenshot() पूरा होने दें; media में वास्तविक PNG bytes या readable stream भेजें; MIME type और extension को PNG के अनुरूप रखें।
  • CI में local screenshot नहीं मिलता: relative path current working directory से resolve होता है। path.resolve() से स्पष्ट path बनाएं या सीधे memory buffer upload करें।
  • Browser launch या navigation fail: पहले Playwright की अपनी browser/navigation error पहचानें; इससे अलग Drive upload तक request पहुंची भी है या नहीं, logs से पुष्टि करें।
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

अगर आपका लक्ष्य सिर्फ किसी URL का screenshot पाना है, तो ScreenshotNeo API एक GET request में PNG, JPEG, WebP या PDF दे सकती है। ScreenshotNeo cookie/consent banners को visitor की तरह स्वीकार कर और 60 से अधिक ज्ञात consent platforms, newsletter popups तथा chat widgets हटाकर साफ shot लेने के लिए बनाई गई है; ये चरण बंद भी किए जा सकते हैं। Bot checks/CAPTCHAs, blank pages, timeouts, failed loads और cache hits पर शुल्क नहीं लगता, और response में X-Page-Verdict तथा X-Billed headers बताते हैं कि क्या हुआ। AI agents के लिए MCP server के tools में take_screenshot, get_page_info और capture_pdf शामिल हैं। Free plan में बिना card 1,000 shots/month हैं; paid plans $5 में 3,000 से शुरू होते हैं।

API key लेकर URL बदलें और response को file में लिखें; अन्य parameters के लिए ScreenshotNeo API docs देखें।

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

बिना card के 1,000 free screenshots प्रति माह के लिए ScreenshotNeo पर sign up करें।

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Frequently Asked Questions

क्या screenshot Drive में सीधे memory से भेज सकता हूं?

हां। page.screenshot() से मिला buffer files.create के media body में दें; इससे local temporary file जरूरी नहीं रहती।

Best Value
Sale
Vansuny 256GB USB C Flash Drive 2 in 1 OTG USB 3.0 + Tape C Memory Stick with Keychain Dual Type C Thumb Drive Photo Stick Jump Drive for Android Smartphones, Computer, Tablet, PC
  • Dual Connectors: The USB-C port can only work on phones/tablets with OTG function. Please make sure your smartphone with OTG function and reversible type-c interface. The other end is USB 3.0 port connecting regular USB devices.[Not for iPhone]
  • Important: Default format of the drive is EXFAT as this is the format recognized by the smartphones and tablets. These drives are only compatible with C-Port enabled mobile phones & computers only. While formatting the drive keep a check on the drive format
  • Fast Speed: High-speed USB 3.0 flash drive for fast data transfer, backwards compatible with USB 2.0,easy to complete the storage and transport functions. You can use it to transfer your computer file or access files from Type-C devices, store and share your photos, videos and music in a simple and reliable way
  • Easy to Use: Plug and play, no need any drive. Used as laptop notebook tablets phones accessories, compatible with Samsung Galaxy Note 8,Galaxy S8,Google Nexus 5X and 6P,Google Pixel XL,New Macbook Pro and more
  • Package includes: 1 pc 256G USB C & USB Multi-function Flash Drive

क्या Google Drive API उसी नाम की पुरानी screenshot file को बदल देती है?

नहीं, इस उदाहरण का files.create नई file बनाता है। अलग runs पहचानने के लिए नाम में timestamp या run ID जोड़ें।

Service account से upload की file मेरे My Drive में क्यों नहीं दिखती?

वह service account की identity/ownership में बनती है। अपने intended destination के लिए sharing, permissions और संगठन की policy पहले व्यवस्थित करें।

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.