Firefox Mobile unable to print (contentWindow is undefined)
- Dominant language
- JavaScript
- Stars
- 4.5k
- Forks
- 688
- PR merge metrics
- No merged PRs in 30d
Description
We are getting following exception on Android 9 Firefox v89.1.1.
No other major problems so far with different mobile or desktop browsers.
print-js version 1.6.0
`contentWindow` is undefined and nothing happens, no print preview and no printed pdf.
```
Unhandled Rejection (TypeError): iframeElement.contentWindow.print is not a function
performPrint
src/js/print.js:66
63 | }
64 | } else {
65 | // Other browsers
> 66 | iframeElement.contentWindow.print()
| ^ 67 | }
68 | } catch (error) {
69 | params.onError(error)
send/iframeElement.onload/<
src/js/print.js:45
42 | const images = printDocument.getElementsByTagName('img')
43 |
44 | if (images.length > 0) {
> 45 | loadIframeImages(Array.from(images)).then(() => performPrint(iframeElement, params))
| ^ 46 | } else {
47 | performPrint(iframeElement, params)
48 | }
promise callback*send/iframeElement.onload
src/js/print.js:45
42 | const images = printDocument.getElementsByTagName('img')
43 |
44 | if (images.length > 0) {
> 45 | loadIframeImages(Array.from(images)).then(() => performPrint(iframeElement, params))
| ^ 46 | } else {
47 | performPrint(iframeElement, params)
48 | }
EventHandlerNonNull*send
src/js/print.js:13
10 | const iframeElement = document.getElementById(params.frameId)
11 |
12 | // Wait for iframe to load all content
> 13 | iframeElement.onload = () => {
| ^ 14 | if (params.type === 'pdf') {
15 | // Add a delay for Firefox. In my tests, 1000ms was sufficient but 100ms was not
16 | if (Browser.isFirefox()) {
print
src/js/raw-html.js:13
10 | params.printableElement.innerHTML = params.printable
11 |
12 | // Print html contents
> 13 | Print.send(params, printFrame)
14 | }
15 | }
16 |
init
src/js/init.js:161
158 | Html.print(params, printFrame)
159 | break
160 | case 'raw-html':
> 161 | RawHtml.print(params, printFrame)
| ^ 162 | break
163 | case 'json':
164 | Json.print(params, printFrame)
print
src/pages/xxx.tsx:465
464 | const print = () => {
> 465 | printJS({
| ^ 466 | printable: rawHtml,
467 | type: 'raw-html',
468 | documentTitle: 'title', // doesn't work on all browsers
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in src/js/print.js, especially performPrint around line 66 and the iframe onload path around lines 13 and 45. Reproduce the raw-html case from src/js/raw-html.js on Android Firefox 89.1.1 and trace why iframeElement.contentWindow.print is unavailable. Done means printing reaches preview or produces the PDF without the reported TypeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100