]> _ Git - fluidbook-toolbox.git/commitdiff
#7398 @0.75
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 3 Apr 2025 09:28:15 +0000 (11:28 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 3 Apr 2025 09:28:15 +0000 (11:28 +0200)
resources/badge/generate_image/generate_image.js
resources/fluidbookpublication/delivery/preview.js
resources/fluidbookpublication/social_screenshot/social_screenshot.js
resources/fluidbooktheme/theme_preview/theme_preview.js
resources/quiztheme/theme_preview/theme_preview.js

index d8e33330b8dd5a2788ab72fce3c02a61237f7f94..50c09cc4322ddaa64d96acc215cc12980146cd8e 100644 (file)
@@ -10,21 +10,32 @@ const optionDefinitions = [
 ];
 
 (async () => {
-    const options = commandLineArgs(optionDefinitions);
-    const browser = await puppeteer.launch({
-        headless: true,
-        args: [
-            "--disable-setuid-sandbox",
-            "--no-sandbox",
-        ],
-        executablePath: 'google-chrome-stable',
-    });
+    try {
+        const options = commandLineArgs(optionDefinitions);
+        const browser = await puppeteer.launch({
+            headless: true,
+            args: [
+                "--disable-setuid-sandbox",
+                "--no-sandbox",
+            ],
+            executablePath: 'google-chrome-stable',
+        });
 
-    const page = await browser.newPage();
-    await page.setViewport({
-        width: options.width / options.scale, height: options.height / options.scale, deviceScaleFactor: options.scale,
-    });
-    await page.goto(options.url, {waitUntil: 'networkidle2'});
-    await page.screenshot({path: options.dest, type: 'png', omitBackground: true});
-    await browser.close();
+        const page = await browser.newPage();
+        await page.setViewport({
+            width: options.width / options.scale,
+            height: options.height / options.scale,
+            deviceScaleFactor: options.scale,
+        });
+        await page.goto(options.url, {waitUntil: 'networkidle2'});
+        await page.screenshot({path: options.dest, type: 'png', omitBackground: true});
+    } catch (e) {
+        console.log(e);
+    } finally {
+        const pages = await browser.pages();
+        for (let i = 0; i < pages.length; i++) {
+            await pages[i].close();
+        }
+        await browser.close();
+    }
 })();
index 4cae7d12322680e09e5702dc13349cce3d604db7..cbb4976e4a90338b92bb8b9c56a090f8c7f08c21 100644 (file)
@@ -11,28 +11,38 @@ const optionDefinitions = [
 ];
 
 (async () => {
-    const options = commandLineArgs(optionDefinitions);
-    const browser = await puppeteer.launch({
-        headless: true,
-        args: [
-            "--disable-setuid-sandbox",
-            "--no-sandbox",
-        ],
-        executablePath: 'google-chrome-stable',
-    });
+    try {
+        const options = commandLineArgs(optionDefinitions);
+        const browser = await puppeteer.launch({
+            headless: true,
+            args: [
+                "--disable-setuid-sandbox",
+                "--no-sandbox",
+            ],
+            executablePath: 'google-chrome-stable',
+        });
 
-    const page = await browser.newPage();
-    await page.setDefaultNavigationTimeout(0);
-    await page.setViewport({
-        width: options.width / options.scale, height: options.height / options.scale, deviceScaleFactor: options.scale,
-    });
-    await page.goto(options.url, {waitUntil: 'networkidle2'});
-    //await page.waitForNavigation();
-    await new Promise(r => setTimeout(r, 1000 * (options.delay + 3)));
-    //
-    await page.evaluate(() => window.fluidbook.setCurrentPage(2));
-    await new Promise(r => setTimeout(r, 1000));
-    await page.screenshot({path: options.dest, type: 'jpeg', quality: 95});
-
-    await browser.close();
+        const page = await browser.newPage();
+        await page.setDefaultNavigationTimeout(0);
+        await page.setViewport({
+            width: options.width / options.scale,
+            height: options.height / options.scale,
+            deviceScaleFactor: options.scale,
+        });
+        await page.goto(options.url, {waitUntil: 'networkidle2'});
+        //await page.waitForNavigation();
+        await new Promise(r => setTimeout(r, 1000 * (options.delay + 3)));
+        //
+        await page.evaluate(() => window.fluidbook.setCurrentPage(2));
+        await new Promise(r => setTimeout(r, 1000));
+        await page.screenshot({path: options.dest, type: 'jpeg', quality: 95});
+    } catch (e) {
+        console.log(e);
+    } finally {
+        const pages = await browser.pages();
+        for (let i = 0; i < pages.length; i++) {
+            await pages[i].close();
+        }
+        await browser.close();
+    }
 })();
index 1c9a1d6c7112329ca8dff25a32c6ca3d7a8f75ec..fdf66e197d0e6def80e6cbbf7070f402d9704cfc 100644 (file)
@@ -10,28 +10,37 @@ const optionDefinitions = [
 ];
 
 (async () => {
-    const options = commandLineArgs(optionDefinitions);
-    const browser = await puppeteer.launch({
-        headless: true,
-        args: [
-            "--disable-setuid-sandbox",
-            "--no-sandbox",
-        ],
-        executablePath: 'google-chrome-stable',
-        protocolTimeout: 18000000,
-    });
-    const page = await browser.newPage();
-    page.on('console', msg => console.log('PAGE LOG:', msg));
-    await page.setViewport({
-        width: options.width / options.scale,
-        height: options.height / options.scale,
-        deviceScaleFactor: options.scale,
-    });
-    await page.setDefaultNavigationTimeout(0);
-    const response = await page.goto(options.url, {waitUntil: 'networkidle2', timeout: 0});
-    if (response.status() === 200) {
-        await new Promise(r => setTimeout(r, 1000 * options.delay));
-        await page.screenshot({path: options.dest, type: 'jpeg', quality: 95});
+    try {
+        const options = commandLineArgs(optionDefinitions);
+        const browser = await puppeteer.launch({
+            headless: true,
+            args: [
+                "--disable-setuid-sandbox",
+                "--no-sandbox",
+            ],
+            executablePath: 'google-chrome-stable',
+            protocolTimeout: 18000000,
+        });
+        const page = await browser.newPage();
+        page.on('console', msg => console.log('PAGE LOG:', msg));
+        await page.setViewport({
+            width: options.width / options.scale,
+            height: options.height / options.scale,
+            deviceScaleFactor: options.scale,
+        });
+        await page.setDefaultNavigationTimeout(0);
+        const response = await page.goto(options.url, {waitUntil: 'networkidle2', timeout: 0});
+        if (response.status() === 200) {
+            await new Promise(r => setTimeout(r, 1000 * options.delay));
+            await page.screenshot({path: options.dest, type: 'jpeg', quality: 95});
+        }
+    } catch (e) {
+        console.log(e);
+    } finally {
+        const pages = await browser.pages();
+        for (let i = 0; i < pages.length; i++) {
+            await pages[i].close();
+        }
+        await browser.close();
     }
-    await browser.close();
 })();
index 0d2c1f3a3e7ec27b23947977c0ca9d33d9fcbab7..7318a8467fa51d9e2927fd6c313db34094492fb9 100644 (file)
@@ -14,57 +14,67 @@ const optionDefinitions = [
 ];
 
 (async () => {
-    const {installMouseHelper} = require('./install-mouse-helper');
-    const options = commandLineArgs(optionDefinitions);
-    const browser = await puppeteer.launch({
-        headless: true,
-        args: [
-            "--disable-setuid-sandbox",
-            "--no-sandbox",
-        ],
-        executablePath: 'google-chrome-stable',
-    });
+    try {
+        const {installMouseHelper} = require('./install-mouse-helper');
+        const options = commandLineArgs(optionDefinitions);
+        const browser = await puppeteer.launch({
+            headless: true,
+            args: [
+                "--disable-setuid-sandbox",
+                "--no-sandbox",
+            ],
+            executablePath: 'google-chrome-stable',
+        });
 
-    const page = await browser.newPage();
-    page.on('console', async (msg) => {
-        const msgArgs = msg.args();
-        for (let i = 0; i < msgArgs.length; ++i) {
-            console.log(await msgArgs[i].jsonValue());
-        }
-    });
-    await page.setViewport({
-        width: options.width / options.scale, height: options.height / options.scale, deviceScaleFactor: options.scale,
-    });
-    await installMouseHelper(page);
-
-    await page.goto(options.url, {waitUntil: 'networkidle2'});
-    await page.screenshot({path: options.destloader, type: 'jpeg', quality: 95});
-    await new Promise(r => setTimeout(r, 1000 * (options.delay + 3)));
-    await page.evaluate(() => console.log(document.body.innerHTML));
-    // Show slider and thumbs
-    await page.evaluate(() => window.fluidbook.slider.hover(512));
-    // Set bookmark on page 3
-    await page.evaluate(() => window.fluidbook.bookmarks.addBookmark(3));
-    // Move to page 2
-    await page.evaluate(() => window.fluidbook.setCurrentPage(2));
-    // Move mouse to hover a link (show tooltip and link)
-    await page.mouse.move(150, 300);
-    // Wait 1s and take a screenshot
-    await new Promise(r => setTimeout(r, 2000));
-    await page.screenshot({path: options.dest, type: 'jpeg', quality: 95});
+        const page = await browser.newPage();
+        page.on('console', async (msg) => {
+            const msgArgs = msg.args();
+            for (let i = 0; i < msgArgs.length; ++i) {
+                console.log(await msgArgs[i].jsonValue());
+            }
+        });
+        await page.setViewport({
+            width: options.width / options.scale,
+            height: options.height / options.scale,
+            deviceScaleFactor: options.scale,
+        });
+        await installMouseHelper(page);
 
-    // Open print menu and take a screenshot
-    await page.evaluate(() => window.fluidbook.slider.leave());
-    await page.evaluate(() => window.fluidbook.menu.openView('print'));
-    await new Promise(r => setTimeout(r, 1000));
-    await page.screenshot({path: options.destmenu, type: 'jpeg', quality: 95});
+        await page.goto(options.url, {waitUntil: 'networkidle2'});
+        await page.screenshot({path: options.destloader, type: 'jpeg', quality: 95});
+        await new Promise(r => setTimeout(r, 1000 * (options.delay + 3)));
+        await page.evaluate(() => console.log(document.body.innerHTML));
+        // Show slider and thumbs
+        await page.evaluate(() => window.fluidbook.slider.hover(512));
+        // Set bookmark on page 3
+        await page.evaluate(() => window.fluidbook.bookmarks.addBookmark(3));
+        // Move to page 2
+        await page.evaluate(() => window.fluidbook.setCurrentPage(2));
+        // Move mouse to hover a link (show tooltip and link)
+        await page.mouse.move(150, 300);
+        // Wait 1s and take a screenshot
+        await new Promise(r => setTimeout(r, 2000));
+        await page.screenshot({path: options.dest, type: 'jpeg', quality: 95});
 
-    // Open burger menu and take a screenshot
-    await page.evaluate(() => window.fluidbook.menu.closeView());
-    await page.evaluate(() => window.fluidbook.nav.menuAPI.open());
-    await new Promise(r => setTimeout(r, 500));
-    await page.mouse.move(60, 400);
-    await page.screenshot({path: options.destburger, type: 'jpeg', quality: 95});
+        // Open print menu and take a screenshot
+        await page.evaluate(() => window.fluidbook.slider.leave());
+        await page.evaluate(() => window.fluidbook.menu.openView('print'));
+        await new Promise(r => setTimeout(r, 1000));
+        await page.screenshot({path: options.destmenu, type: 'jpeg', quality: 95});
 
-    await browser.close();
+        // Open burger menu and take a screenshot
+        await page.evaluate(() => window.fluidbook.menu.closeView());
+        await page.evaluate(() => window.fluidbook.nav.menuAPI.open());
+        await new Promise(r => setTimeout(r, 500));
+        await page.mouse.move(60, 400);
+        await page.screenshot({path: options.destburger, type: 'jpeg', quality: 95});
+    } catch (e) {
+        console.log(e);
+    } finally {
+        const pages = await browser.pages();
+        for (let i = 0; i < pages.length; i++) {
+            await pages[i].close();
+        }
+        await browser.close();
+    }
 })();
index 87e9a6d4093c47628c717d897db03475d80ef59c..c12b90fe50414c5339fa689701b1e0f1b91a6c2e 100644 (file)
@@ -14,48 +14,58 @@ const optionDefinitions = [
 ];
 
 (async () => {
-    const options = commandLineArgs(optionDefinitions);
-    const browser = await puppeteer.launch({
-        headless: 'new',
-        args: [
-            "--disable-setuid-sandbox",
-            "--no-sandbox",
-        ],
-        executablePath: 'google-chrome-stable',
-    });
+    try {
+        const options = commandLineArgs(optionDefinitions);
+        const browser = await puppeteer.launch({
+            headless: 'new',
+            args: [
+                "--disable-setuid-sandbox",
+                "--no-sandbox",
+            ],
+            executablePath: 'google-chrome-stable',
+        });
 
-    const page = await browser.newPage();
-    page.on('console', async (msg) => {
-        const msgArgs = msg.args();
-        for (let i = 0; i < msgArgs.length; ++i) {
-            console.log(await msgArgs[i].jsonValue());
-        }
-    });
-    await page.setViewport({
-        width: options.width / options.scale, height: options.height / options.scale, deviceScaleFactor: options.scale,
-    });
-
-    // Intro screen
-    await page.goto(options.url, {waitUntil: 'networkidle2'});
-    await new Promise(r => setTimeout(r, 1000 * (options.delay + 5)));
-    await page.screenshot({path: options.intro, type: 'jpeg', quality: 95});
+        const page = await browser.newPage();
+        page.on('console', async (msg) => {
+            const msgArgs = msg.args();
+            for (let i = 0; i < msgArgs.length; ++i) {
+                console.log(await msgArgs[i].jsonValue());
+            }
+        });
+        await page.setViewport({
+            width: options.width / options.scale,
+            height: options.height / options.scale,
+            deviceScaleFactor: options.scale,
+        });
 
-    // Question 1
-    await page.evaluate(() => window.quiz.screens.showScreen('q-0'));
-    await new Promise(r => setTimeout(r, 1000 * (options.delay + 3)));
-    await page.screenshot({path: options.standard, type: 'jpeg', quality: 95});
-    await page.evaluate(() => window.quiz.score.setAnswer(0, [0]));
+        // Intro screen
+        await page.goto(options.url, {waitUntil: 'networkidle2'});
+        await new Promise(r => setTimeout(r, 1000 * (options.delay + 5)));
+        await page.screenshot({path: options.intro, type: 'jpeg', quality: 95});
 
-    // Question 2
-    await page.evaluate(() => window.quiz.screens.showScreen('q-1'));
-    await new Promise(r => setTimeout(r, 1000 * (options.delay + 3)));
-    await page.screenshot({path: options.draganddrop, type: 'jpeg', quality: 95});
-    await page.evaluate(() => window.quiz.score.setAnswer(1, [1, 1, 2, 1, 2]));
+        // Question 1
+        await page.evaluate(() => window.quiz.screens.showScreen('q-0'));
+        await new Promise(r => setTimeout(r, 1000 * (options.delay + 3)));
+        await page.screenshot({path: options.standard, type: 'jpeg', quality: 95});
+        await page.evaluate(() => window.quiz.score.setAnswer(0, [0]));
 
-    // Outro
-    await page.evaluate(() => window.quiz.screens.showScreen('outro'));
-    await new Promise(r => setTimeout(r, 1000 * (options.delay + 3)));
-    await page.screenshot({path: options.outro, type: 'jpeg', quality: 95});
+        // Question 2
+        await page.evaluate(() => window.quiz.screens.showScreen('q-1'));
+        await new Promise(r => setTimeout(r, 1000 * (options.delay + 3)));
+        await page.screenshot({path: options.draganddrop, type: 'jpeg', quality: 95});
+        await page.evaluate(() => window.quiz.score.setAnswer(1, [1, 1, 2, 1, 2]));
 
-    await browser.close();
+        // Outro
+        await page.evaluate(() => window.quiz.screens.showScreen('outro'));
+        await new Promise(r => setTimeout(r, 1000 * (options.delay + 3)));
+        await page.screenshot({path: options.outro, type: 'jpeg', quality: 95});
+    } catch (e) {
+        console.log(e);
+    } finally {
+        const pages = await browser.pages();
+        for (let i = 0; i < pages.length; i++) {
+            await pages[i].close();
+        }
+        await browser.close();
+    }
 })();