|
1 | 1 |
|
2 | 2 | import { toArray, choose, reverse, chunkBySize, iterateIndexed, indexed, iterate, filter as filter_1, collect as collect_1, length, truncate, mapIndexed, append, exists as exists_1, map, empty, cons, tail, head, isEmpty, singleton as singleton_1, tryFind, ofArray } from "./fable_modules/fable-library-js.5.19.0/List.js"; |
3 | | -import { requireFromHome, childProcess, readDir, remove, eprint, run as run_1, writeBytes, fromJs, deliver, extname, fsp, awaitJs, sep as sep_3, join, engineDir, http, resolve, exists, env } from "./Node.js"; |
| 3 | +import { requireFromHome, closingOnError, childProcess, readDir, remove, eprint, run as run_1, writeBytes, deliver, extname, fsp, awaitJs, sep as sep_3, join, engineDir, http, resolve, fromJs, exists, env } from "./Node.js"; |
4 | 4 | import { Operators_IsNull } from "./fable_modules/fable-library-js.5.19.0/FSharp.Core.js"; |
5 | 5 | import { defaultArg, value as value_9, ofNullable } from "./fable_modules/fable-library-js.5.19.0/Option.js"; |
| 6 | +import { singleton } from "./fable_modules/fable-library-js.5.19.0/AsyncBuilder.js"; |
6 | 7 | import { Record, Union } from "./fable_modules/fable-library-js.5.19.0/Types.js"; |
7 | 8 | import { tuple_type, obj_type, option_type, list_type, int32_type, float64_type, class_type, bool_type, record_type, lambda_type, unit_type, string_type, union_type } from "./fable_modules/fable-library-js.5.19.0/Reflection.js"; |
8 | 9 | import { empty as empty_2, FSharpMap__Add, FSharpMap__Remove, FSharpMap__TryFind, tryFind as tryFind_1, ofSeq } from "./fable_modules/fable-library-js.5.19.0/Map.js"; |
9 | 10 | import { disposeSafe, getEnumerator, int32ToString, Exception, equals, comparePrimitives } from "./fable_modules/fable-library-js.5.19.0/Util.js"; |
10 | | -import { singleton } from "./fable_modules/fable-library-js.5.19.0/AsyncBuilder.js"; |
11 | 11 | import { padLeft, join as join_1, split, concat, substring } from "./fable_modules/fable-library-js.5.19.0/String.js"; |
12 | 12 | import { parallel, fromContinuations } from "./fable_modules/fable-library-js.5.19.0/Async.js"; |
13 | 13 | import { post, postAndAsyncReply, receive, start as start_1 } from "./fable_modules/fable-library-js.5.19.0/MailboxProcessor.js"; |
@@ -61,6 +61,18 @@ export function releaseChrome(browser) { |
61 | 61 | } |
62 | 62 | } |
63 | 63 |
|
| 64 | +/** |
| 65 | + * Closes a browser after a failure, as far as it can: one that has crashed may not answer. |
| 66 | + */ |
| 67 | +export function closeQuietly(browser) { |
| 68 | + return singleton.Delay(() => singleton.Combine(singleton.TryWith(singleton.Delay(() => singleton.Bind(fromJs(browser.close()), () => singleton.Return(undefined))), (_arg_1) => { |
| 69 | + return singleton.Zero(); |
| 70 | + }), singleton.Delay(() => { |
| 71 | + releaseChrome(browser); |
| 72 | + return singleton.Zero(); |
| 73 | + }))); |
| 74 | +} |
| 75 | + |
64 | 76 | /** |
65 | 77 | * Who the server is for. The scan's server (scan.mjs) differs on purpose: it answers 404 for .wav (no audio is |
66 | 78 | * needed to scan), knows fewer types, and sends no cache header. Its 404s show up in scan.json's logs, so keep them. |
@@ -647,23 +659,30 @@ function withChrome(clip, job) { |
647 | 659 | const matchValue = findChrome(); |
648 | 660 | if (matchValue != null) { |
649 | 661 | const chrome = matchValue; |
650 | | - const puppeteer = requireFromHome("puppeteer-core"); |
651 | | - return singleton.Bind(fromJs(puppeteer.launch({ |
652 | | - executablePath: chrome, |
653 | | - headless: true, |
654 | | - args: ["--font-render-hinting=none", "--force-color-profile=srgb", "--autoplay-policy=no-user-gesture-required"], |
655 | | - })), (_arg_1) => { |
656 | | - const browser = _arg_1; |
657 | | - const session = Session_$ctor_Z6861C5C0(browser, server.Url); |
658 | | - return singleton.Bind(Session__OpenPage(session), (_arg_2) => singleton.Bind(job(session, _arg_2), (_arg_3) => { |
659 | | - const code = _arg_3 | 0; |
660 | | - return singleton.Bind(fromJs(browser.close()), () => { |
661 | | - releaseChrome(browser); |
662 | | - server.Close(); |
663 | | - return singleton.Bind(Session__IsFailed(session), (_arg_5) => singleton.Return((code !== 0) ? code : (_arg_5 ? 1 : 0))); |
664 | | - }); |
665 | | - })); |
666 | | - }); |
| 662 | + return singleton.ReturnFrom(closingOnError(() => singleton.Delay(() => { |
| 663 | + server.Close(); |
| 664 | + return singleton.Zero(); |
| 665 | + }), singleton.Delay(() => { |
| 666 | + const puppeteer = requireFromHome("puppeteer-core"); |
| 667 | + return singleton.Bind(fromJs(puppeteer.launch({ |
| 668 | + executablePath: chrome, |
| 669 | + headless: true, |
| 670 | + args: ["--font-render-hinting=none", "--force-color-profile=srgb", "--autoplay-policy=no-user-gesture-required"], |
| 671 | + })), (_arg_1) => { |
| 672 | + const browser = _arg_1; |
| 673 | + return singleton.ReturnFrom(closingOnError(() => closeQuietly(browser), singleton.Delay(() => { |
| 674 | + const session = Session_$ctor_Z6861C5C0(browser, server.Url); |
| 675 | + return singleton.Bind(Session__OpenPage(session), (_arg_2) => singleton.Bind(job(session, _arg_2), (_arg_3) => { |
| 676 | + const code = _arg_3 | 0; |
| 677 | + return singleton.Bind(fromJs(browser.close()), () => { |
| 678 | + releaseChrome(browser); |
| 679 | + server.Close(); |
| 680 | + return singleton.Bind(Session__IsFailed(session), (_arg_5) => singleton.Return((code !== 0) ? code : (_arg_5 ? 1 : 0))); |
| 681 | + }); |
| 682 | + })); |
| 683 | + }))); |
| 684 | + }); |
| 685 | + }))); |
667 | 686 | } |
668 | 687 | else { |
669 | 688 | eprint("no Chrome found: set CHROME to the browser\'s executable"); |
|
0 commit comments