homebridge-melcloud-control 4.0.0-beta.537 → 4.0.0-beta.539

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/melcloud.js +16 -41
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "4.0.0-beta.537",
4
+ "version": "4.0.0-beta.539",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
package/src/melcloud.js CHANGED
@@ -331,7 +331,7 @@ class MelCloud extends EventEmitter {
331
331
 
332
332
  this.emit('warn', `Launching Chromium...`);
333
333
  browser = await puppeteer.launch({
334
- headless: 'shell',
334
+ headless: 'new',
335
335
  executablePath: chromiumPath,
336
336
  timeout: GLOBAL_TIMEOUT,
337
337
  args: [
@@ -344,47 +344,22 @@ class MelCloud extends EventEmitter {
344
344
  ]
345
345
  });
346
346
 
347
- try {
348
- // go to about:blank to ensure a clean origin
349
- await page.goto('about:blank');
350
-
351
- // prefer context-based clear if available
352
- const pageContext = (typeof page.browserContext === 'function') ? page.browserContext() : (page.context ? page.context() : null);
353
-
354
- if (pageContext && typeof pageContext.clearCookies === 'function') {
355
- // modern API in some puppeteer versions
356
- await pageContext.clearCookies();
357
- } else {
358
- // try CDP directly (works in most environments)
359
- if (page._client && typeof page._client === 'function') {
360
- const client = await page._client();
361
- if (client && client.send) {
362
- await client.send('Network.clearBrowserCookies');
363
- } else if (page._client && page._client.send) {
364
- // some versions expose _client directly as object
365
- await page._client.send('Network.clearBrowserCookies');
366
- } else {
367
- // fallback to deleting cookies returned by page.cookies()
368
- const cookies = await page.cookies();
369
- if (cookies && cookies.length) {
370
- await page.deleteCookie(...cookies).catch(() => { });
371
- }
372
- }
373
- } else if (page._client && page._client.send) {
374
- // older shape where _client is object
375
- await page._client.send('Network.clearBrowserCookies');
376
- } else {
377
- // final fallback
378
- const cookies = await page.cookies();
379
- if (cookies && cookies.length) {
380
- await page.deleteCookie(...cookies).catch(() => { });
381
- }
382
- }
383
- }
384
- } catch (clearErr) {
385
- // nie przerywamy procesu logowania jeśli clear cookies nie zadziała, logujemy tylko warn
386
- this.emit('warn', `Failed to clear cookies cleanly: ${clearErr.message}`);
347
+ let context;
348
+ if (typeof browser.createBrowserContext === 'function') {
349
+ // nowoczesne API
350
+ context = await browser.createBrowserContext();
351
+ } else {
352
+ // fallback do starego API (dla bezpieczeństwa)
353
+ context = browser.defaultBrowserContext?.() || browser;
387
354
  }
355
+
356
+ const page = await context.newPage();
357
+
358
+ // --- wyczyszczenie cookies ---
359
+ const client = await page.createCDPSession();
360
+ await client.send('Network.clearBrowserCookies');
361
+
362
+ await page.goto('about:blank');
388
363
  page.setDefaultTimeout(GLOBAL_TIMEOUT);
389
364
  page.setDefaultNavigationTimeout(GLOBAL_TIMEOUT);
390
365