mirror of
https://github.com/spacedeck/spacedeck-open.git
synced 2025-12-15 09:27:31 +01:00
replaced phantomjs with puppeteer
started to replace phantomjs with puppeteer
This commit is contained in:
14
Dockerfile
14
Dockerfile
@@ -21,6 +21,20 @@ RUN cd audiowaveform/build/ && cmake -D ENABLE_TESTS=0 -D BUILD_STATIC=1 ..
|
||||
RUN cd audiowaveform/build/ && make
|
||||
RUN cd audiowaveform/build/ && make install
|
||||
|
||||
# install chromium
|
||||
RUN apk add --no-cache \
|
||||
chromium \
|
||||
nss \
|
||||
freetype \
|
||||
freetype-dev \
|
||||
harfbuzz \
|
||||
ca-certificates \
|
||||
ttf-freefont
|
||||
|
||||
# Tell Puppeteer to skip installing Chrome. We'll be using the installed package.
|
||||
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
|
||||
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
|
||||
|
||||
# install other requirements
|
||||
|
||||
RUN apk add graphicsmagick ffmpeg ffmpeg-dev ghostscript
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
const db = require('../models/db');
|
||||
const config = require('config');
|
||||
const phantom = require('node-phantom-simple');
|
||||
const puppeteer = require('puppeteer');
|
||||
const os = require('os');
|
||||
|
||||
module.exports = {
|
||||
@@ -25,46 +25,44 @@ module.exports = {
|
||||
|
||||
var on_exit = function(exit_code) {
|
||||
if (exit_code>0) {
|
||||
console.error("phantom abnormal exit for url "+space_url);
|
||||
console.error(exit_code);
|
||||
console.error("puppeteer abnormal exit for url "+space_url);
|
||||
if (!on_success_called && on_error) {
|
||||
on_error();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
phantom.create({ path: require('phantomjs-prebuilt').path }, function (err, browser) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
} else {
|
||||
return browser.createPage(function (err, page) {
|
||||
(async () => {
|
||||
let browser;
|
||||
let page;
|
||||
try {
|
||||
browser = await puppeteer.launch(
|
||||
{
|
||||
headless: true,
|
||||
args: ['--disable-dev-shm-usage', '--no-sandbox']
|
||||
}
|
||||
);
|
||||
page = await browser.newPage();
|
||||
|
||||
page.setDefaultTimeout(timeout);
|
||||
await page.setJavaScriptEnabled(false);
|
||||
|
||||
console.log("page created, opening ",space_url);
|
||||
await page.goto(space_url, {waitUntil: 'networkidle0'});
|
||||
|
||||
if (type=="pdf") {
|
||||
var psz = {
|
||||
width: space.width+"px",
|
||||
height: space.height+"px"
|
||||
};
|
||||
page.set('paperSize', psz);
|
||||
await page.pdf({path: export_path, width: space.width+'px', height: space.height+'px' });
|
||||
}else{
|
||||
await page.screenshot({path: export_path});
|
||||
}
|
||||
|
||||
page.set('settings.resourceTimeout',timeout);
|
||||
page.set('settings.javascriptEnabled',false);
|
||||
|
||||
return page.open(space_url, function (err,status) {
|
||||
page.render(export_path, function() {
|
||||
on_success_called = true;
|
||||
if (on_success) {
|
||||
await browser.close();
|
||||
on_success(export_path);
|
||||
}
|
||||
page.close();
|
||||
browser.exit();
|
||||
});
|
||||
});
|
||||
});
|
||||
} catch (error) {
|
||||
on_error();
|
||||
}
|
||||
|
||||
}, {
|
||||
onExit: on_exit
|
||||
});
|
||||
})();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
"node-phantom-simple": "2.2.4",
|
||||
"node-server-screenshot": "^0.2.1",
|
||||
"nodemailer": "^4.6.7",
|
||||
"phantomjs-prebuilt": "^2.1.16",
|
||||
"puppeteer": "3.0.0",
|
||||
"read-chunk": "^2.1.0",
|
||||
"request": "^2.88.0",
|
||||
"sanitize-html": "^1.11.1",
|
||||
|
||||
Reference in New Issue
Block a user