canvasxpress-cli 63.1.1 → 63.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/cmds/io.js CHANGED
@@ -2,7 +2,7 @@ const util = require('util');
2
2
  const path = require('path');
3
3
  const fs = require('fs');
4
4
  const ora = require('ora');
5
- const puppeteer = require('puppeteer');
5
+ const { chromium } = require('playwright');
6
6
 
7
7
  module.exports = async (obj) => {
8
8
 
@@ -30,39 +30,31 @@ module.exports = async (obj) => {
30
30
 
31
31
  try {
32
32
 
33
- const browser = await puppeteer.launch({
33
+ const browser = await chromium.launch({
34
34
  headless: obj.debug ? false : true,
35
35
  devtools: obj.debug ? true : false,
36
- executablePath: puppeteer.executablePath(),
37
- defaultViewport: {
38
- width: 1000,
39
- height: 1000
40
- },
41
36
  args: ['--no-sandbox',
42
37
  '--allow-file-access-from-files',
43
38
  '--enable-local-file-accesses']
44
39
  });
45
40
 
46
- const page = await browser.newPage();
47
-
48
- // Print All
49
- //page.on("console", (consoleObj) => console.log(consoleObj.text()));
41
+ const context = await browser.newContext({
42
+ viewport: { width: 1000, height: 1000 }
43
+ });
50
44
 
51
- // Print All except warnings
52
- page.on('console', consoleObj => {
53
- if (consoleObj.type() !== 'warning') {
54
- console.log(consoleObj.text());
55
- }
45
+ await context.route('**/*', route => {
46
+ route.continue({ headers: { ...route.request().headers() } });
56
47
  });
57
48
 
58
- /*
59
- // Print only logs
49
+ const page = await context.newPage();
50
+
51
+ await page.context().setDefaultDownloadDirectory(obj.output);
52
+
60
53
  page.on('console', consoleObj => {
61
- if (consoleObj.type() === 'log') {
62
- console.log(consoleObj.text());
54
+ if (consoleObj.type() !== 'warning') {
55
+ console.log(consoleObj.text());
63
56
  }
64
57
  });
65
- */
66
58
 
67
59
  if (obj.input && !obj.input.match(/^file|^http/)) {
68
60
  obj.input = "file://" + path.resolve(obj.input);
@@ -107,7 +99,7 @@ module.exports = async (obj) => {
107
99
  cx.dataURL = obj.input;
108
100
  cx.remoteTransitionEffect = 'none';
109
101
  cx.getDataFromURLOrString(obj.target || cx.target, obj.config, false, false, clbk);
110
- } else {
102
+ } else {
111
103
  console.log("Creating " + (obj.cmd == 'csv' ? 'png' : obj.cmd) + " file from " + (obj.input ? obj.input : 'input data') + " (" + obj.output + (obj.target || cx.target) + "." + obj.cmd + ")");
112
104
  exec(cx, obj.target || cx.target);
113
105
  }
@@ -128,25 +120,37 @@ module.exports = async (obj) => {
128
120
  }
129
121
  }
130
122
 
131
- await page._client.send('Page.setDownloadBehavior', {
132
- behavior: 'allow',
133
- downloadPath: obj.output
123
+ const downloadDir = path.resolve(obj.output);
124
+ await page.route('**/*', async route => {
125
+ const response = await route.fetch();
126
+ const headers = response.headers();
127
+ if (headers['content-disposition'] && headers['content-disposition'].includes('attachment')) {
128
+ const buffer = await response.body();
129
+ const disposition = headers['content-disposition'];
130
+ const match = disposition.match(/filename="?([^"]+)"?/);
131
+ const filename = match ? match[1] : 'download';
132
+ fs.writeFileSync(path.join(downloadDir, filename), buffer);
133
+ route.abort();
134
+ } else {
135
+ route.continue();
136
+ }
134
137
  });
135
138
 
136
- if (obj.input) {
137
- await page.goto(obj.cmd == 'csv' ? defhtml : obj.cmd == 'reproduce' ? obj.input + '?showTransition=false' : obj.input);
138
- } else {
139
- await page.goto(defhtml);
140
- }
139
+ const targetUrl = obj.input
140
+ ? (obj.cmd == 'csv' ? defhtml : obj.cmd == 'reproduce' ? obj.input + '?showTransition=false' : obj.input)
141
+ : defhtml;
142
+
143
+ await page.goto(targetUrl, { waitUntil: 'networkidle' });
141
144
 
142
- await page.waitFor(() => typeof (CanvasXpress) !== undefined && CanvasXpress.ready);
145
+ await page.waitForFunction(() => typeof CanvasXpress !== 'undefined' && CanvasXpress.ready);
143
146
 
144
147
  await page.evaluate(`(${func.toString()})(${JSON.stringify(obj)})`);
145
148
 
146
- await setTimeout(() => {
147
- browser.close();
148
- spinner.stop();
149
- }, obj.cmd == 'csv' || obj.cmd == 'reproduce' ? obj.tmout + 2500 : obj.tmout);
149
+ const delay = obj.cmd == 'csv' || obj.cmd == 'reproduce' ? obj.tmout + 2500 : obj.tmout;
150
+ await page.waitForTimeout(delay);
151
+
152
+ await browser.close();
153
+ spinner.stop();
150
154
 
151
155
  } catch (err) {
152
156
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvasxpress-cli",
3
- "version": "63.1.1",
3
+ "version": "63.2.0",
4
4
  "license": {
5
5
  "type": "Dual licensing",
6
6
  "url": "https://www.canvasxpress.org/docs/license.html"