Вот моя программа mapCreate.php
Код: Выделить всё
Код: Выделить всё
import puppeteer from 'puppeteer';
//const puppeteer = require('puppeteer-extra');
import StealthPlugin from 'puppeteer-extra-plugin-stealth';
//const StealthPlugin = require('puppeteer-extra-plugin-stealth');
import sharp from 'sharp';
//const sharp = require('sharp');
import http from 'http';
import https from 'https';
//puppeteer.use(StealthPlugin());
//const { executablePath } = require('puppeteer')
import { executablePath } from 'puppeteer';
puppeteer.launch({ headless: true, args: ['--no-sandbox'], executablePath: executablePath() }).then(async browser => {
console.log('Running tests..');
const page = await browser.newPage();
// Retrieve HOST_NAME from command-line arguments
const HOST_NAME = process.argv[2];
// process.argv[0] is the path to node, process.argv[1] is the path to the script
// Check if HOST_NAME is provided
if (!HOST_NAME) {
console.error('HOST_NAME is not provided.');
process.exit(1); // Exit the script with an error code
}
// Set a large viewport size
await page.setViewport({ width: 1920, height: 1080 });
await page.goto('https://monitoring.minutuscloud.com/zabbix/');
await page.type('#name', 'Admin');
await page.type('#password', 'zabb!x@Minutus');
await page.click('[type=submit]');
await page.waitForTimeout(2000);
await page.click('.icon-monitoring');
await page.waitForTimeout(2000);
await page.evaluate(() => {
const mapsLink = Array.from(document.querySelectorAll('a')).find(a => a.textContent.includes('Maps'));
mapsLink.click();
});
await page.waitForTimeout(2000);
// Use HOST_NAME within page.evaluate()
await page.evaluate((HOST_NAME) => {
const mapLink = Array.from(document.querySelectorAll('a')).find(a => a.textContent.includes(HOST_NAME));
if (mapLink) { // Check if mapLink is found before clicking
mapLink.click();
} else {
console.error('Map link not found.');
}
}, HOST_NAME);
await page.waitForTimeout(2000)
// Scroll to the bottom of the page
await page.evaluate(() => {
window.scrollTo(0, document.body.scrollHeight);
});
await page.waitForTimeout(2000);
// Capture a full-page screenshot
await page.screenshot({ path: '/tmp/testresult.png', fullPage: true });
await browser.close();
sharp('/tmp/testresult.png')
.extract({ left: 200, top: 80, width: 1700, height: 800 })
.toFile('/tmp/test-new.jpg', function (err) {
if (err) console.log(err);
})
console.log(`All done, check the screenshot. ✨`);
});
ошибок нет, у меня был файл js вместо node.mjs, где вместо импорта были операторы require (закомментированные). Даже это имело такое же поведение.
Подробнее здесь: https://stackoverflow.com/questions/781 ... s-no-effec