publishport-opencli 1.0.53 → 1.0.54

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.
@@ -23,6 +23,10 @@ export declare class DebuggerBanner {
23
23
  private readonly warn;
24
24
  private readonly idleMs;
25
25
  private anchorTabId;
26
+ private anchorTargetId;
27
+ /** An ensureAnchor run is already queued: further commands need not queue another. */
28
+ private ensurePending;
29
+ private noCandidateUntil;
26
30
  private idleTimer;
27
31
  private queue;
28
32
  /** Target ids used by commands: their attachment belongs to the command, never anchor there. */
@@ -39,6 +43,13 @@ export declare class DebuggerBanner {
39
43
  shutdown(): void;
40
44
  /** Extension connection closed: nothing can be sent any more. */
41
45
  dispose(): void;
46
+ /**
47
+ * Every command reports activity, and a busy profile can have hundreds of tabs and frames:
48
+ * listing all debugger targets per command kept Chrome's browser process and the extension
49
+ * busy. Queue at most one check, and list targets only when no anchor is held, the anchor
50
+ * tab was taken over by a command, or the no-candidate back-off has expired.
51
+ */
52
+ private scheduleEnsure;
42
53
  private enqueue;
43
54
  private expect;
44
55
  private rememberCommandTarget;
@@ -1 +1 @@
1
- export const BANNER_IDLE_MS=300000,BANNER_CAPABILITIES=["chrome-api","events"];const s="publishport:banner-anchor",r=500;export function supportsDebuggerBanner(t){return BANNER_CAPABILITIES.every((e)=>t.includes(e))}export class DebuggerBanner{call;warn;idleMs;anchorTabId=null;idleTimer=null;queue=Promise.resolve();commandTargets=new Set;active=!1;disposed=!1;constructor(t,e,a=BANNER_IDLE_MS){this.call=t;this.warn=e;this.idleMs=a}start(){return this.enqueue(async()=>{await this.expect(this.call({action:"events",events:[{name:"debugger.onDetach"}]}),"subscribe debugger.onDetach");const e=(await this.expect(this.call({action:"chrome-api",api:"storage.session.get",args:[s]}),"read stored anchor"))?.[s];if(typeof e==="number"&&!this.active)await this.detach(e)})}onActivity(t){if(this.disposed)return;if(t)this.rememberCommandTarget(t);this.active=!0;if(this.idleTimer)clearTimeout(this.idleTimer);this.idleTimer=setTimeout(()=>{this.idleTimer=null;this.active=!1;this.enqueue(()=>this.releaseAnchor())},this.idleMs);this.idleTimer.unref?.();this.enqueue(()=>this.ensureAnchor())}onEvent(t,e){if(this.disposed||t!=="debugger.onDetach"||!Array.isArray(e))return;const a=e[0];if(typeof a?.tabId!=="number"||a.tabId!==this.anchorTabId)return;this.anchorTabId=null;if(e[1]==="canceled_by_user")return;if(this.active)this.enqueue(()=>this.ensureAnchor())}shutdown(){this.active=!1;if(this.idleTimer)clearTimeout(this.idleTimer);this.idleTimer=null;const t=this.anchorTabId;this.anchorTabId=null;this.disposed=!0;if(t!==null)this.call({action:"chrome-api",api:"debugger.detach",args:[{tabId:t}]}).catch((e)=>{this.warn(`[daemon] debugger banner: detach on shutdown failed: ${e instanceof Error?e.message:String(e)}`)})}dispose(){this.disposed=!0;if(this.idleTimer)clearTimeout(this.idleTimer);this.idleTimer=null}enqueue(t){this.queue=this.queue.then(t).catch((e)=>{this.warn(`[daemon] debugger banner: ${e instanceof Error?e.message:String(e)}`)});return this.queue}async expect(t,e){const a=await t;if(!a?.ok)throw Error(`${e} failed: ${a?.error??"no result"}`);return a.data??null}rememberCommandTarget(t){this.commandTargets.delete(t);this.commandTargets.add(t);if(this.commandTargets.size>r){const e=this.commandTargets.values().next().value;if(e!==void 0)this.commandTargets.delete(e)}}async ensureAnchor(){if(!this.active||this.disposed)return;const t=await this.expect(this.call({action:"chrome-api",api:"debugger.getTargets"}),"list debugger targets");if(this.anchorTabId!==null){const a=t.find((i)=>i.tabId===this.anchorTabId);if(a?.attached&&!this.commandTargets.has(a.id))return;this.anchorTabId=null}const e=t.filter((a)=>a.type==="page"&&typeof a.tabId==="number"&&/^https?:/.test(a.url)&&!a.attached&&!this.commandTargets.has(a.id)).sort((a,i)=>a.tabId-i.tabId);for(const a of e){const i=a.tabId;if(!(await this.call({action:"chrome-api",api:"debugger.attach",args:[{tabId:i},"1.3"]}))?.ok)continue;this.anchorTabId=i;await this.expect(this.call({action:"chrome-api",api:"storage.session.set",args:[{[s]:i}]}),"store anchor");return}this.warn("[daemon] debugger banner: no http(s) tab available to hold the debugger session")}async releaseAnchor(){if(this.active||this.anchorTabId===null)return;const t=this.anchorTabId;this.anchorTabId=null;await this.detach(t)}async detach(t){const e=await this.call({action:"chrome-api",api:"debugger.detach",args:[{tabId:t}]});if(!e?.ok&&!/not attached|No tab with given id/i.test(e?.error??""))throw Error(`detach anchor ${t} failed: ${e?.error??"no result"}`);await this.expect(this.call({action:"chrome-api",api:"storage.session.remove",args:[s]}),"clear stored anchor")}}
1
+ export const BANNER_IDLE_MS=300000,BANNER_CAPABILITIES=["chrome-api","events"];const s="publishport:banner-anchor",r=500,n=30000;export function supportsDebuggerBanner(t){return BANNER_CAPABILITIES.every((e)=>t.includes(e))}export class DebuggerBanner{call;warn;idleMs;anchorTabId=null;anchorTargetId=null;ensurePending=!1;noCandidateUntil=0;idleTimer=null;queue=Promise.resolve();commandTargets=new Set;active=!1;disposed=!1;constructor(t,e,a=BANNER_IDLE_MS){this.call=t;this.warn=e;this.idleMs=a}start(){return this.enqueue(async()=>{await this.expect(this.call({action:"events",events:[{name:"debugger.onDetach"}]}),"subscribe debugger.onDetach");const e=(await this.expect(this.call({action:"chrome-api",api:"storage.session.get",args:[s]}),"read stored anchor"))?.[s];if(typeof e==="number"&&!this.active)await this.detach(e)})}onActivity(t){if(this.disposed)return;if(t)this.rememberCommandTarget(t);this.active=!0;if(this.idleTimer)clearTimeout(this.idleTimer);this.idleTimer=setTimeout(()=>{this.idleTimer=null;this.active=!1;this.enqueue(()=>this.releaseAnchor())},this.idleMs);this.idleTimer.unref?.();this.scheduleEnsure()}onEvent(t,e){if(this.disposed||t!=="debugger.onDetach"||!Array.isArray(e))return;const a=e[0];if(typeof a?.tabId!=="number"||a.tabId!==this.anchorTabId)return;this.anchorTabId=null;this.anchorTargetId=null;if(e[1]==="canceled_by_user")return;if(this.active)this.scheduleEnsure()}shutdown(){this.active=!1;if(this.idleTimer)clearTimeout(this.idleTimer);this.idleTimer=null;const t=this.anchorTabId;this.anchorTabId=null;this.anchorTargetId=null;this.disposed=!0;if(t!==null)this.call({action:"chrome-api",api:"debugger.detach",args:[{tabId:t}]}).catch((e)=>{this.warn(`[daemon] debugger banner: detach on shutdown failed: ${e instanceof Error?e.message:String(e)}`)})}dispose(){this.disposed=!0;if(this.idleTimer)clearTimeout(this.idleTimer);this.idleTimer=null}scheduleEnsure(){if(this.ensurePending)return;if(this.anchorTabId!==null&&!(this.anchorTargetId&&this.commandTargets.has(this.anchorTargetId)))return;if(this.anchorTabId===null&&Date.now()<this.noCandidateUntil)return;this.ensurePending=!0;this.enqueue(async()=>{this.ensurePending=!1;await this.ensureAnchor()})}enqueue(t){this.queue=this.queue.then(t).catch((e)=>{this.warn(`[daemon] debugger banner: ${e instanceof Error?e.message:String(e)}`)});return this.queue}async expect(t,e){const a=await t;if(!a?.ok)throw Error(`${e} failed: ${a?.error??"no result"}`);return a.data??null}rememberCommandTarget(t){this.commandTargets.delete(t);this.commandTargets.add(t);if(this.commandTargets.size>r){const e=this.commandTargets.values().next().value;if(e!==void 0)this.commandTargets.delete(e)}}async ensureAnchor(){if(!this.active||this.disposed)return;const t=await this.expect(this.call({action:"chrome-api",api:"debugger.getTargets"}),"list debugger targets");if(this.anchorTabId!==null){const a=t.find((i)=>i.tabId===this.anchorTabId);if(a?.attached&&!this.commandTargets.has(a.id))return;this.anchorTabId=null;this.anchorTargetId=null}const e=t.filter((a)=>a.type==="page"&&typeof a.tabId==="number"&&/^https?:/.test(a.url)&&!a.attached&&!this.commandTargets.has(a.id)).sort((a,i)=>a.tabId-i.tabId);for(const a of e){const i=a.tabId;if(!(await this.call({action:"chrome-api",api:"debugger.attach",args:[{tabId:i},"1.3"]}))?.ok)continue;this.anchorTabId=i;this.anchorTargetId=a.id;await this.expect(this.call({action:"chrome-api",api:"storage.session.set",args:[{[s]:i}]}),"store anchor");return}this.noCandidateUntil=Date.now()+n;this.warn("[daemon] debugger banner: no http(s) tab available to hold the debugger session")}async releaseAnchor(){if(this.active||this.anchorTabId===null)return;const t=this.anchorTabId;this.anchorTabId=null;this.anchorTargetId=null;await this.detach(t)}async detach(t){const e=await this.call({action:"chrome-api",api:"debugger.detach",args:[{tabId:t}]});if(!e?.ok&&!/not attached|No tab with given id/i.test(e?.error??""))throw Error(`detach anchor ${t} failed: ${e?.error??"no result"}`);await this.expect(this.call({action:"chrome-api",api:"storage.session.remove",args:[s]}),"clear stored anchor")}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "publishport-opencli",
3
- "version": "1.0.53",
3
+ "version": "1.0.54",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": false