polotno-node 2.1.0 → 2.2.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/README.md +76 -7
- package/dist/{client.7c21efff.js → client.3517c032.js} +54 -46
- package/dist/client.html +1 -1
- package/instance.js +16 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -141,12 +141,24 @@ const url = await instance.jsonToDataURL(json, { pixelRatio: 0.2 });
|
|
|
141
141
|
// const url = await store.toDataURL({ pixelRatio: 0.2 });
|
|
142
142
|
```
|
|
143
143
|
|
|
144
|
-
|
|
144
|
+
### `attrs.assetLoadTimeout`
|
|
145
|
+
|
|
146
|
+
You can add `assetLoadTimeout` attribute to `attrs` object. It will be used to set timeout for loading assets (images, fonts, etc). By default it is 30000ms.
|
|
145
147
|
|
|
146
148
|
```js
|
|
147
149
|
const url = await instance.jsonToPDFDataURL(json, { assetLoadTimeout: 60000 });
|
|
148
150
|
```
|
|
149
151
|
|
|
152
|
+
### `attrs.htmlTextRenderEnabled`
|
|
153
|
+
|
|
154
|
+
Enabled experimental HTML text rendering. By default it is `false`.
|
|
155
|
+
|
|
156
|
+
```js
|
|
157
|
+
const url = await instance.jsonToPDFDataURL(json, {
|
|
158
|
+
htmlTextRenderEnabled: true,
|
|
159
|
+
});
|
|
160
|
+
```
|
|
161
|
+
|
|
150
162
|
### `instance.run()`
|
|
151
163
|
|
|
152
164
|
Run any Polotno store API directly inside web-page context.
|
|
@@ -206,9 +218,15 @@ const instance = await createInstance({
|
|
|
206
218
|
});
|
|
207
219
|
```
|
|
208
220
|
|
|
209
|
-
##
|
|
221
|
+
## Usage on the cloud
|
|
222
|
+
|
|
223
|
+
`polotno-node` should work by default on AWS Lambda. But in some cloud providers you may need to do extra steps to reduce function size.
|
|
210
224
|
|
|
211
|
-
|
|
225
|
+
### Browserless usage
|
|
226
|
+
|
|
227
|
+
You can speed up your function execution a lot, if instead of using full browser you will use [browserless.io](https://browserless.io/) service. It is a paid service not affiliated with Polotno.
|
|
228
|
+
|
|
229
|
+
Using browserless.io you can also make your function much smaller in size, so it will be possible to deploy to cloud provider with smaller limits, like Vercel.
|
|
212
230
|
|
|
213
231
|
```js
|
|
214
232
|
const { createInstance } = require('polotno-node/instance');
|
|
@@ -222,20 +240,71 @@ const instance = await createInstance({
|
|
|
222
240
|
});
|
|
223
241
|
```
|
|
224
242
|
|
|
243
|
+
### Minimal usage
|
|
244
|
+
|
|
245
|
+
Also you can use [@sparticuz/chromium-min](https://github.com/Sparticuz/chromium#-min-package) to reduce function size. Make sure it is caching chromium binary in your cloud provider. Looks like Vercel is NOT doing that!
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
npm install @sparticuz/chromium-min
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
```js
|
|
252
|
+
const { createInstance } = require('polotno-node/instance');
|
|
253
|
+
const chromium = require('@sparticuz/chromium-min');
|
|
254
|
+
const puppeteer = require('puppeteer-core');
|
|
255
|
+
|
|
256
|
+
const makeInstance = async () => {
|
|
257
|
+
const browser = await puppeteer.launch({
|
|
258
|
+
args: [
|
|
259
|
+
...chromium.args,
|
|
260
|
+
'--no-sandbox',
|
|
261
|
+
'--hide-scrollbars',
|
|
262
|
+
'--disable-web-security',
|
|
263
|
+
'--allow-file-access-from-files',
|
|
264
|
+
// more info about --disable-dev-shm-usage
|
|
265
|
+
// https://github.com/puppeteer/puppeteer/issues/1175#issuecomment-369728215
|
|
266
|
+
// https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#tips
|
|
267
|
+
'--disable-dev-shm-usage',
|
|
268
|
+
],
|
|
269
|
+
defaultViewport: chromium.defaultViewport,
|
|
270
|
+
executablePath: await chromium.executablePath(
|
|
271
|
+
'https://github.com/Sparticuz/chromium/releases/download/v110.0.1/chromium-v110.0.1-pack.tar'
|
|
272
|
+
),
|
|
273
|
+
headless: chromium.headless,
|
|
274
|
+
ignoreHTTPSErrors: true,
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
return await createInstance({
|
|
278
|
+
key: 'your-key',
|
|
279
|
+
browser,
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
const instance = await makeInstance();
|
|
284
|
+
```
|
|
285
|
+
|
|
225
286
|
## Troubleshooting
|
|
226
287
|
|
|
227
288
|
If you have an error like this
|
|
228
289
|
|
|
229
290
|
```
|
|
230
|
-
|
|
291
|
+
|
|
292
|
+
Unhandled Promise Rejection {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"Error: Evaluation failed: ReferenceError: store is not defined\n at **puppeteer_evaluation_script**:3:9"
|
|
293
|
+
|
|
231
294
|
```
|
|
232
295
|
|
|
233
296
|
It may mean that Polotno Client Editor was not loaded in `puppeteer` instance. It is possible that you are missing required files in `node_modules` folder. I got this error when I was trying to run `polotno-node` on Vercel. To fix the issue you need to add this config into `vercel.json`:
|
|
234
297
|
|
|
235
298
|
```
|
|
299
|
+
|
|
236
300
|
"functions": {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
301
|
+
"api/render.js": { // remember to replace this line with your function name
|
|
302
|
+
"includeFiles": "node_modules/polotno-node/\*\*"
|
|
303
|
+
},
|
|
240
304
|
}
|
|
305
|
+
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
```
|
|
309
|
+
|
|
241
310
|
```
|