Tiện ích mở rộng trình duyệt
Nâng cao trải nghiệm và phiên duyệt web của bạn với Scrapeless thông qua các tiện ích mở rộng trình duyệt tùy chỉnh.
APIs
- Tải lên tiện ích mở rộng:
POST /extensions/upload
- Cập nhật tiện ích mở rộng:
PUT /extensions/{extensionId}
- Xóa tiện ích mở rộng:
DELETE /extensions/{extensionId}
- Lấy danh sách tiện ích mở rộng:
GET /extensions/list
- Lấy thông tin tiện ích mở rộng:
GET /extensions/{extensionId}
Tham khảo tài liệu API để xem chi tiết.
Thiết lập tiện ích mở rộng trình duyệt
Sử dụng tham số extension_ids
để chỉ định ID tiện ích mở rộng để thiết lập tiện ích mở rộng trình duyệt. Sử dụng dấu phẩy để phân tách nhiều ID tiện ích mở rộng.
Ví dụ: extension_ids=extension_id1,extension_id2
Ví dụ về Tiện ích mở rộng
Mã ví dụ này minh họa cách tải lên tiện ích mở rộng MetaMask thông qua API và chỉ định tải nó khi khởi chạy trình duyệt.
// npm install @scrapeless-ai/sdk puppeteer-core
import { Scrapeless } from '@scrapeless-ai/sdk';
import puppeteer from 'puppeteer-core';
const API_TOKEN = 'API Key'; // replace with your API Key
const EXTENSION_FILE_PATH = '/extensions/metamask-chrome-12.20.0.zip'; // replace with your extension zip file path
const client = new Scrapeless({ apiKey: API_TOKEN });
const { browser: scrapingBrowser } = client;
(async () => {
try {
const uploadResponse = await scrapingBrowser.extension.upload(EXTENSION_FILE_PATH, 'metamask'); // extension name
const extensionId = uploadResponse?.extensionId;
const { browserWSEndpoint } = scrapingBrowser.create({
session_name: 'use-extension',
session_ttl: 180,
extension_ids: extensionId, // setup browser extension, separate by comma for multiple extensions
});
const browser = await puppeteer.connect({
browserWSEndpoint,
defaultViewport: null
});
const page = await browser.newPage();
await page.goto('chrome://extensions/');
await page.screenshot({
path: 'extensions-screenshot.png',
fullPage: true
});
await browser.close();
} catch (error) {
console.error('Error:', error.response?.data || error.message);
}
})()
Bạn có thể kiểm tra xem các tiện ích mở rộng đã được tải thành công hay chưa bằng cách truy cập trang chrome://extensions
.
Kết quả có thể được nhìn thấy như bên dưới: