@jbrowse/capture 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +124 -0
- package/esm/args.d.ts +30 -0
- package/esm/args.js +79 -0
- package/esm/bin.d.ts +2 -0
- package/esm/bin.js +165 -0
- package/esm/browser.d.ts +4 -0
- package/esm/browser.js +53 -0
- package/esm/capture.d.ts +113 -0
- package/esm/capture.js +273 -0
- package/esm/hub.d.ts +23 -0
- package/esm/hub.js +43 -0
- package/esm/index.d.ts +10 -0
- package/esm/index.js +7 -0
- package/esm/session.d.ts +25 -0
- package/esm/session.js +61 -0
- package/esm/sessionGate.d.ts +126 -0
- package/esm/sessionGate.js +196 -0
- package/esm/url.d.ts +39 -0
- package/esm/url.js +44 -0
- package/esm/waits.d.ts +214 -0
- package/esm/waits.js +428 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [2020] [Evolutionary Software Foundation]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# @jbrowse/capture
|
|
2
|
+
|
|
3
|
+
Drive a live JBrowse 2 instance with Puppeteer and screenshot it **once it has
|
|
4
|
+
actually finished rendering**.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
npx @jbrowse/capture --hub hg38 --loc BRCA1 \
|
|
8
|
+
--track hg38-ncbiRefSeqCurated --track hg38-phyloP100way -o brca1.png
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
`--hub` names an assembly on [genomes.jbrowse.org](https://genomes.jbrowse.org),
|
|
12
|
+
which hosts a ready-made JBrowse config per UCSC and GenArk genome, and `--loc`
|
|
13
|
+
takes a gene name because those configs ship a text index.
|
|
14
|
+
|
|
15
|
+
## Knowing when JBrowse has finished rendering
|
|
16
|
+
|
|
17
|
+
Knowing when a genome browser is done is the entire problem. JBrowse loads its
|
|
18
|
+
config, builds a session, resolves an assembly, fetches each track, and then
|
|
19
|
+
draws to a canvas — and a screenshot taken at any point before the last step is
|
|
20
|
+
a picture of an empty browser that looks like a successful run.
|
|
21
|
+
|
|
22
|
+
Every readiness signal JBrowse publishes is **negative**: no loading overlay, no
|
|
23
|
+
display in its loading phase, no unpainted canvas. All of them therefore pass on
|
|
24
|
+
a page whose JavaScript has not started yet. Measured against
|
|
25
|
+
`jbrowse.org/code/jb2/latest`:
|
|
26
|
+
|
|
27
|
+
- `networkidle2` resolves at ~350ms
|
|
28
|
+
- the session appears at ~880ms
|
|
29
|
+
- the assembly and tracks land at ~2500ms
|
|
30
|
+
- the loading overlay only goes up _after that_
|
|
31
|
+
|
|
32
|
+
A wait chain built from those signals alone finishes in under a second and
|
|
33
|
+
reports success.
|
|
34
|
+
|
|
35
|
+
So this package puts a **positive gate** in front of them, read off the live MST
|
|
36
|
+
session model that jbrowse-web publishes as `window.JBrowseSession`: the session
|
|
37
|
+
exists, its views are initialized, and the assembly and trackIds you asked for
|
|
38
|
+
are the ones actually open. A config URL that 404s, a trackId the config does
|
|
39
|
+
not define, and an assembly name that does not match all fail there, loudly.
|
|
40
|
+
|
|
41
|
+
## Library
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
import { captureJBrowse, openJBrowse } from '@jbrowse/capture'
|
|
45
|
+
|
|
46
|
+
// one call: launch, wait, shoot, close
|
|
47
|
+
const { pending, paintContract } = await captureJBrowse({
|
|
48
|
+
hub: 'hg38',
|
|
49
|
+
loc: 'BRCA1',
|
|
50
|
+
tracks: ['hg38-ncbiRefSeqCurated'],
|
|
51
|
+
out: 'brca1.png',
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
// or keep the page, to click things and read state back
|
|
55
|
+
const { browser, page } = await openJBrowse({ hub: 'mm39', loc: 'Sox2' })
|
|
56
|
+
const tracks = await page.evaluate(
|
|
57
|
+
() => window.JBrowseSession.views[0].tracks.length,
|
|
58
|
+
)
|
|
59
|
+
await browser.close()
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Two waits, depending on what you did:
|
|
63
|
+
|
|
64
|
+
- **`waitForJBrowseReady(page)`** is the wait on its own, for a page you
|
|
65
|
+
navigated yourself. The individual stages (`waitForSession`,
|
|
66
|
+
`waitForLoadingComplete`, `waitForDisplaysDone`, `waitForQuiescent`, ...) are
|
|
67
|
+
exported too, and each one documents what it can and cannot tell you.
|
|
68
|
+
- **`waitForAppSettled(page)`** is the wait after you CLICK something. A page
|
|
69
|
+
that is loading starts out `loading` and the transition into `ready` is it
|
|
70
|
+
finishing; a page you just clicked is already `ready` and stays that way until
|
|
71
|
+
the click's work registers, so waiting for `ready` there returns on the
|
|
72
|
+
pre-click frame. `waitForAppSettled` requires it to hold.
|
|
73
|
+
|
|
74
|
+
## Timeouts and unsettled waits
|
|
75
|
+
|
|
76
|
+
Puppeteer waits are usually written `.catch(() => {})` so a slow page is not
|
|
77
|
+
failed for being slow. The cost is that "everything settled" and "we gave up"
|
|
78
|
+
become the same `void` — the run ends with an image and an exit code of 0 either
|
|
79
|
+
way, which is the vacuous-gate problem again, one step later.
|
|
80
|
+
|
|
81
|
+
Here every stage reports its outcome, and an unsettled one throws by default,
|
|
82
|
+
naming the gate:
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
gave up waiting after 2000ms: the loading overlay never cleared (a track fetch
|
|
86
|
+
never finished). Raise the timeout if the page is merely slow; if it never
|
|
87
|
+
finishes, open the same URL in a browser — this gate has no content to fall
|
|
88
|
+
through to.
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`allowUnsettled` (`--allowUnsettled`) takes the frame as it stands instead, and
|
|
92
|
+
still tells you what did not settle.
|
|
93
|
+
|
|
94
|
+
## Reading the result
|
|
95
|
+
|
|
96
|
+
Three fields on a successful capture:
|
|
97
|
+
|
|
98
|
+
- **`unsettled`** — stages that hit their timeout. Empty unless you asked to
|
|
99
|
+
proceed anyway.
|
|
100
|
+
- **`pending`** — displays still reporting unpainted when the shutter fired. A
|
|
101
|
+
display can return to pending after its stage passed, so this is a separate
|
|
102
|
+
question from `unsettled`.
|
|
103
|
+
- **`paintContract`** — whether this JBrowse build publishes the per-display
|
|
104
|
+
paint attributes at all. It does not on the current released build, which is
|
|
105
|
+
what every genomes.jbrowse.org link opens; there, `pending: []` means "cannot
|
|
106
|
+
tell", not "all done", and the CLI says so. A page with no tracks open reports
|
|
107
|
+
true — there is nothing to measure, which is not the same as being unable to.
|
|
108
|
+
|
|
109
|
+
## CLI
|
|
110
|
+
|
|
111
|
+
`jb2capture --help` for the full list. Also:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
jb2capture list hg38 conservation # trackIds matching a filter
|
|
115
|
+
jb2capture url --hub hg38 --loc BRCA1 # just print the link, no browser
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## See also
|
|
119
|
+
|
|
120
|
+
- [@jbrowse/img](https://www.npmjs.com/package/@jbrowse/img) renders SVG/PNG
|
|
121
|
+
with no browser at all, via server-side React. Prefer it for a static figure;
|
|
122
|
+
use this when you need the real app — canvas and WebGPU rendering, dialogs,
|
|
123
|
+
menus, or state read back out of a running session.
|
|
124
|
+
- [Using JBrowse with AI agents](https://jbrowse.org/jb2/docs/agents/)
|
package/esm/args.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface ParsedArgs {
|
|
2
|
+
hub?: string;
|
|
3
|
+
config?: string;
|
|
4
|
+
assembly?: string;
|
|
5
|
+
loc?: string;
|
|
6
|
+
tracks: string[];
|
|
7
|
+
session?: string;
|
|
8
|
+
sessionName?: string;
|
|
9
|
+
instance?: string;
|
|
10
|
+
out?: string;
|
|
11
|
+
width?: number;
|
|
12
|
+
height?: number;
|
|
13
|
+
scale?: number;
|
|
14
|
+
timeout?: number;
|
|
15
|
+
settle?: number;
|
|
16
|
+
fullPage: boolean;
|
|
17
|
+
headed: boolean;
|
|
18
|
+
verbose: boolean;
|
|
19
|
+
help: boolean;
|
|
20
|
+
allowUnsettled: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Parse `jb2capture` flags. Split from the binary so the accepted shapes are
|
|
24
|
+
* unit-testable without launching a browser.
|
|
25
|
+
*
|
|
26
|
+
* Unknown flags throw rather than being ignored: a mistyped `--tracks` on a tool
|
|
27
|
+
* whose whole job is to produce a plausible-looking image would otherwise be
|
|
28
|
+
* reported by nothing at all.
|
|
29
|
+
*/
|
|
30
|
+
export declare function parseArgs(argv: string[]): ParsedArgs;
|
package/esm/args.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
const NUMERIC = new Set(['width', 'height', 'scale', 'timeout', 'settle']);
|
|
2
|
+
const FLAGS = new Set([
|
|
3
|
+
'fullPage',
|
|
4
|
+
'headed',
|
|
5
|
+
'verbose',
|
|
6
|
+
'help',
|
|
7
|
+
'allowUnsettled',
|
|
8
|
+
]);
|
|
9
|
+
const REPEATABLE = new Set(['track']);
|
|
10
|
+
const STRINGS = new Set([
|
|
11
|
+
'hub',
|
|
12
|
+
'config',
|
|
13
|
+
'assembly',
|
|
14
|
+
'loc',
|
|
15
|
+
'session',
|
|
16
|
+
'sessionName',
|
|
17
|
+
'instance',
|
|
18
|
+
'out',
|
|
19
|
+
]);
|
|
20
|
+
// `--fullPage`, not `--full-page`: the flags match the option names in the
|
|
21
|
+
// library API one for one, so a script and a command line say the same thing.
|
|
22
|
+
// Aliases are the two abbreviations that are hard not to type.
|
|
23
|
+
const ALIASES = { o: 'out', h: 'help' };
|
|
24
|
+
function known(name) {
|
|
25
|
+
return (NUMERIC.has(name) ||
|
|
26
|
+
FLAGS.has(name) ||
|
|
27
|
+
REPEATABLE.has(name) ||
|
|
28
|
+
STRINGS.has(name));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Parse `jb2capture` flags. Split from the binary so the accepted shapes are
|
|
32
|
+
* unit-testable without launching a browser.
|
|
33
|
+
*
|
|
34
|
+
* Unknown flags throw rather than being ignored: a mistyped `--tracks` on a tool
|
|
35
|
+
* whose whole job is to produce a plausible-looking image would otherwise be
|
|
36
|
+
* reported by nothing at all.
|
|
37
|
+
*/
|
|
38
|
+
export function parseArgs(argv) {
|
|
39
|
+
const out = { tracks: [] };
|
|
40
|
+
for (const flag of FLAGS) {
|
|
41
|
+
out[flag] = false;
|
|
42
|
+
}
|
|
43
|
+
for (let i = 0; i < argv.length; i++) {
|
|
44
|
+
const arg = argv[i];
|
|
45
|
+
if (!arg.startsWith('-')) {
|
|
46
|
+
throw new Error(`unexpected argument "${arg}"`);
|
|
47
|
+
}
|
|
48
|
+
const bare = arg.replace(/^--?/, '');
|
|
49
|
+
const eq = bare.indexOf('=');
|
|
50
|
+
const rawName = eq === -1 ? bare : bare.slice(0, eq);
|
|
51
|
+
const name = ALIASES[rawName] ?? rawName;
|
|
52
|
+
if (!known(name)) {
|
|
53
|
+
throw new Error(`unknown flag "${arg}"`);
|
|
54
|
+
}
|
|
55
|
+
if (FLAGS.has(name)) {
|
|
56
|
+
out[name] = true;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const value = eq === -1 ? argv[++i] : bare.slice(eq + 1);
|
|
60
|
+
if (value === undefined) {
|
|
61
|
+
throw new Error(`--${name} needs a value`);
|
|
62
|
+
}
|
|
63
|
+
if (REPEATABLE.has(name)) {
|
|
64
|
+
;
|
|
65
|
+
out.tracks.push(value);
|
|
66
|
+
}
|
|
67
|
+
else if (NUMERIC.has(name)) {
|
|
68
|
+
const n = Number(value);
|
|
69
|
+
if (!Number.isFinite(n)) {
|
|
70
|
+
throw new Error(`--${name} needs a number, got "${value}"`);
|
|
71
|
+
}
|
|
72
|
+
out[name] = n;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
out[name] = value;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return out;
|
|
79
|
+
}
|
package/esm/bin.d.ts
ADDED
package/esm/bin.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { parseArgs } from './args.js';
|
|
4
|
+
import { captureJBrowse } from './capture.js';
|
|
5
|
+
import { listHubTracks } from './hub.js';
|
|
6
|
+
import { PAINT_CONTRACT_NOTE } from './sessionGate.js';
|
|
7
|
+
import { jbrowseUrl } from './url.js';
|
|
8
|
+
const HELP = `jb2capture — screenshot a live JBrowse 2 view, once it has finished drawing
|
|
9
|
+
|
|
10
|
+
USAGE
|
|
11
|
+
jb2capture [flags] --out <file.png> open a view, wait for it, screenshot it
|
|
12
|
+
jb2capture url [flags] print the URL instead of launching a browser
|
|
13
|
+
jb2capture list <hub> [filter] list a hosted assembly's trackIds
|
|
14
|
+
|
|
15
|
+
WHAT TO SHOW
|
|
16
|
+
--hub <name> a genomes.jbrowse.org assembly: a UCSC db name (hg38, mm39)
|
|
17
|
+
or a GenArk accession (GCA_.../GCF_...)
|
|
18
|
+
--config <url> a config.json URL, for data that is not hosted there
|
|
19
|
+
--assembly <name> assembly to open (defaults to --hub)
|
|
20
|
+
--loc <locstring> where to go: chr1:1,000-2,000, or several space-separated
|
|
21
|
+
for a discontinuous view. On a config with a text index —
|
|
22
|
+
every UCSC assembly on genomes.jbrowse.org has one — a
|
|
23
|
+
gene name such as BRCA1 also works.
|
|
24
|
+
--track <trackId> a track to open; repeat for several
|
|
25
|
+
--session <json|path> a full session spec, for several views or per-display
|
|
26
|
+
settings. Replaces --assembly/--loc/--track.
|
|
27
|
+
--instance <url> JBrowse Web deployment to drive
|
|
28
|
+
(default https://jbrowse.org/code/jb2/latest/)
|
|
29
|
+
--sessionName <name> name the opened session carries
|
|
30
|
+
|
|
31
|
+
THE IMAGE
|
|
32
|
+
--out, -o <file> PNG to write (required unless using a subcommand)
|
|
33
|
+
--width <px> viewport width (default 1400)
|
|
34
|
+
--height <px> viewport height (default 900)
|
|
35
|
+
--scale <n> device pixel ratio (default 2)
|
|
36
|
+
--fullPage capture the whole scrollable page, not just the viewport
|
|
37
|
+
|
|
38
|
+
WAITING
|
|
39
|
+
--timeout <ms> budget per wait stage (default 60000)
|
|
40
|
+
--settle <ms> extra pause after everything reports drawn (default 0)
|
|
41
|
+
--allowUnsettled write the image anyway when a stage times out
|
|
42
|
+
|
|
43
|
+
Every stage is waited on for you: the session holding the assembly and tracks
|
|
44
|
+
you asked for, the view resolving, tracks fetching, displays painting, and any
|
|
45
|
+
leftover "Loading…" text. A stage that times out FAILS the run rather than
|
|
46
|
+
quietly handing back a half-drawn frame — raise --timeout, or pass
|
|
47
|
+
--allowUnsettled if you want the frame as it stands.
|
|
48
|
+
|
|
49
|
+
OTHER
|
|
50
|
+
--headed run with a visible browser window
|
|
51
|
+
--verbose print browser console output (GPU noise filtered)
|
|
52
|
+
--help, -h this text
|
|
53
|
+
|
|
54
|
+
EXAMPLES
|
|
55
|
+
## RefSeq genes and ClinVar at a gene, from hosted data, no setup
|
|
56
|
+
jb2capture --hub hg38 --loc BRCA1 \\
|
|
57
|
+
--track hg38-ncbiRefSeqCurated --track hg38-clinvarMain -o brca1.png
|
|
58
|
+
|
|
59
|
+
## find the trackIds first
|
|
60
|
+
jb2capture list hg38 conservation
|
|
61
|
+
|
|
62
|
+
## your own config, two loci side by side
|
|
63
|
+
jb2capture --config https://example.org/config.json --assembly mydata \\
|
|
64
|
+
--loc "chr3:25,325,000-25,361,000 chr10:58,716,500-58,718,500" -o two.png
|
|
65
|
+
`;
|
|
66
|
+
function readSession(value) {
|
|
67
|
+
const text = value.trimStart().startsWith('{')
|
|
68
|
+
? value
|
|
69
|
+
: readFileSync(value, 'utf8');
|
|
70
|
+
const parsed = JSON.parse(text);
|
|
71
|
+
if (typeof parsed !== 'object' || parsed === null) {
|
|
72
|
+
throw new Error('--session must be a JSON object');
|
|
73
|
+
}
|
|
74
|
+
return parsed;
|
|
75
|
+
}
|
|
76
|
+
function urlOptions(args) {
|
|
77
|
+
return {
|
|
78
|
+
hub: args.hub,
|
|
79
|
+
config: args.config,
|
|
80
|
+
assembly: args.assembly,
|
|
81
|
+
loc: args.loc,
|
|
82
|
+
tracks: args.tracks.length ? args.tracks : undefined,
|
|
83
|
+
session: args.session ? readSession(args.session) : undefined,
|
|
84
|
+
sessionName: args.sessionName,
|
|
85
|
+
instance: args.instance,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
async function runList(rest) {
|
|
89
|
+
const [hub, filter] = rest;
|
|
90
|
+
if (!hub) {
|
|
91
|
+
throw new Error('list needs an assembly, e.g. `jb2capture list hg38`. ' +
|
|
92
|
+
'Browse them at https://genomes.jbrowse.org.');
|
|
93
|
+
}
|
|
94
|
+
const tracks = await listHubTracks(hub, filter);
|
|
95
|
+
if (!tracks.length) {
|
|
96
|
+
throw new Error(filter
|
|
97
|
+
? `no track in ${hub} matches "${filter}"`
|
|
98
|
+
: `${hub} publishes no tracks`);
|
|
99
|
+
}
|
|
100
|
+
const pad = Math.min(60, Math.max(...tracks.map(t => t.trackId.length)));
|
|
101
|
+
for (const t of tracks) {
|
|
102
|
+
console.log(` ${t.trackId.padEnd(pad)} ${(t.type ?? '').padEnd(18)} ${t.name ?? ''}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async function main() {
|
|
106
|
+
const argv = process.argv.slice(2);
|
|
107
|
+
const [first, ...rest] = argv;
|
|
108
|
+
if (first === 'list') {
|
|
109
|
+
await runList(rest);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const isUrlOnly = first === 'url';
|
|
113
|
+
const args = parseArgs(isUrlOnly ? rest : argv);
|
|
114
|
+
if (args.help || argv.length === 0) {
|
|
115
|
+
console.log(HELP);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (isUrlOnly) {
|
|
119
|
+
console.log(jbrowseUrl(urlOptions(args)));
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (!args.out) {
|
|
123
|
+
throw new Error('--out <file.png> is required (or use `jb2capture url`)');
|
|
124
|
+
}
|
|
125
|
+
const { url, pending, paintContract, unsettled } = await captureJBrowse({
|
|
126
|
+
...urlOptions(args),
|
|
127
|
+
out: args.out,
|
|
128
|
+
width: args.width,
|
|
129
|
+
height: args.height,
|
|
130
|
+
deviceScaleFactor: args.scale,
|
|
131
|
+
fullPage: args.fullPage,
|
|
132
|
+
headless: !args.headed,
|
|
133
|
+
timeout: args.timeout,
|
|
134
|
+
settleMs: args.settle,
|
|
135
|
+
allowUnsettled: args.allowUnsettled,
|
|
136
|
+
onConsole: args.verbose
|
|
137
|
+
? text => {
|
|
138
|
+
console.error(` [page] ${text}`);
|
|
139
|
+
}
|
|
140
|
+
: undefined,
|
|
141
|
+
});
|
|
142
|
+
console.log(`wrote ${args.out}`);
|
|
143
|
+
console.log(`from ${url}`);
|
|
144
|
+
// Reached only when the wait either succeeded or was explicitly overridden, so
|
|
145
|
+
// these are notes on an image that exists rather than failures. They still get
|
|
146
|
+
// said out loud: "everything painted", "we stopped waiting" and "paint could
|
|
147
|
+
// not be measured here" all look identical in a PNG.
|
|
148
|
+
if (unsettled.length) {
|
|
149
|
+
console.error(`warning: --allowUnsettled: ${unsettled.join('; ')}`);
|
|
150
|
+
}
|
|
151
|
+
if (pending.length) {
|
|
152
|
+
console.error(`warning: ${pending.length} display(s) had not finished drawing at capture time ` +
|
|
153
|
+
`(${pending.join(', ')}). Raise --timeout, or --settle for a slow remote file.`);
|
|
154
|
+
}
|
|
155
|
+
else if (!paintContract) {
|
|
156
|
+
console.error(`note: ${PAINT_CONTRACT_NOTE}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
await main();
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
console.error(`jb2capture: ${error instanceof Error ? error.message : error}`);
|
|
164
|
+
process.exitCode = 1;
|
|
165
|
+
}
|
package/esm/browser.d.ts
ADDED
package/esm/browser.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
// Just the sandbox flags, for the scripts that MEASURE cross-origin behaviour
|
|
3
|
+
// (COOP/COEP isolation, cancelled cross-origin fetches) and would be measuring
|
|
4
|
+
// nothing with web security off. They used to spell this
|
|
5
|
+
// `BASE_CHROME_ARGS.filter(a => a !== '--disable-web-security')`, which silently
|
|
6
|
+
// stops subtracting the day another security flag is added below.
|
|
7
|
+
export const SANDBOX_CHROME_ARGS = ['--no-sandbox', '--disable-setuid-sandbox'];
|
|
8
|
+
// Chrome flags both harnesses launch with. Backend-specific flags
|
|
9
|
+
// (--disable-gpu, --enable-unsafe-swiftshader, --disable-popup-blocking) are
|
|
10
|
+
// appended by each caller.
|
|
11
|
+
export const BASE_CHROME_ARGS = [
|
|
12
|
+
...SANDBOX_CHROME_ARGS,
|
|
13
|
+
'--disable-web-security',
|
|
14
|
+
];
|
|
15
|
+
const CHROME_PATHS = [
|
|
16
|
+
'/usr/bin/google-chrome',
|
|
17
|
+
'/usr/bin/chromium-browser',
|
|
18
|
+
'/usr/bin/chromium',
|
|
19
|
+
];
|
|
20
|
+
// First installed system Chrome/Chromium, or undefined to let Puppeteer use its
|
|
21
|
+
// bundled browser. `CHROME_PATH` wins, so a run can be pinned to one binary --
|
|
22
|
+
// which is how you answer "did the browser move under us?" when a figure regen
|
|
23
|
+
// reports the whole corpus as changed.
|
|
24
|
+
//
|
|
25
|
+
// Measured 2026-08-02, because that question came up and the answer was no: the
|
|
26
|
+
// same spec rendered under Chrome 147.0.7727.57 and 151.0.7922.47 produces
|
|
27
|
+
// byte-identical PNGs, and the system package's 151.0.7922.47 -> .71 roll
|
|
28
|
+
// likewise changed nothing. So a corpus-wide diff is accumulated app change
|
|
29
|
+
// since the last `Bump snaps` sweep, not the browser -- don't chase it here.
|
|
30
|
+
export function findChromeExecutable() {
|
|
31
|
+
return process.env.CHROME_PATH ?? CHROME_PATHS.find(p => fs.existsSync(p));
|
|
32
|
+
}
|
|
33
|
+
// GPU/WebGL lifecycle chatter that isn't a real error. Real GPU failures
|
|
34
|
+
// (`context LOST`, `GL error`) are deliberately NOT suppressed.
|
|
35
|
+
const NOISE_NEEDLES = [
|
|
36
|
+
'favicon',
|
|
37
|
+
'GPU stall',
|
|
38
|
+
'[GPU] WebGPU not supported',
|
|
39
|
+
'[GPU] No compatible GPU adapter',
|
|
40
|
+
'[GPU] WebGPU initialization failed',
|
|
41
|
+
'[GPU] WebGL2 unavailable',
|
|
42
|
+
'[GPU] WebGPU device creation failed',
|
|
43
|
+
'GroupMarkerNotSet',
|
|
44
|
+
'Automatic fallback to software WebGL',
|
|
45
|
+
'No available adapters',
|
|
46
|
+
'Failed to create WebGPU Context Provider',
|
|
47
|
+
];
|
|
48
|
+
export function isBrowserConsoleNoise(text) {
|
|
49
|
+
if (text.includes('[WebGL2Hal #')) {
|
|
50
|
+
return !text.includes('context LOST') && !text.includes('GL error');
|
|
51
|
+
}
|
|
52
|
+
return NOISE_NEEDLES.some(n => text.includes(n));
|
|
53
|
+
}
|