MCPcopy
hub / github.com/027xiguapi/code-box / printContentInIFrame

Method printContentInIFrame

utils/print.ts:143–182  ·  view source on GitHub ↗
(
    content: string,
    options: PrintOptions
  )

Source from the content-addressed store, hash-verified

141 }
142
143 private static printContentInIFrame(
144 content: string,
145 options: PrintOptions
146 ): Promise<void> {
147 return new Promise((resolve, reject) => {
148 const iframe = document.createElement("iframe")
149 document.body.appendChild(iframe)
150 iframe.style.position = "absolute"
151 iframe.style.top = "-9999px"
152 iframe.style.left = "-9999px"
153
154 const frameWindow = iframe.contentWindow
155 if (!frameWindow) {
156 reject(new Error("Unable to get iframe window"))
157 return
158 }
159
160 const frameDoc = frameWindow.document
161 frameDoc.open()
162 frameDoc.write(options.doctype + content)
163 frameDoc.close()
164
165 frameWindow.onload = () => {
166 try {
167 frameWindow.focus()
168 frameWindow.print()
169 document.body.removeChild(iframe)
170 resolve()
171 } catch (error) {
172 reject(error)
173 }
174 }
175
176 setTimeout(() => {
177 frameWindow.print()
178 document.body.removeChild(iframe)
179 resolve()
180 }, options.timeout)
181 })
182 }
183
184 private static printContentInNewWindow(
185 content: string,

Callers 1

printMethod · 0.80

Calls 1

printMethod · 0.80

Tested by

no test coverage detected