@skillcdn/console 0.4.5 → 0.4.6

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/src/plugin/web.ts CHANGED
@@ -51,6 +51,13 @@ export interface FrameWindow {
51
51
  };
52
52
  addEventListener(type: "message", listener: (event: FrameMessageEvent) => void): void;
53
53
  removeEventListener(type: "message", listener: (event: FrameMessageEvent) => void): void;
54
+ /**
55
+ * The browser's own way to open a window, which it holds to a press in the frame (ADR-0078).
56
+ * A frame of a console before 0.4.6 has one too, whose sandbox lets it open nothing.
57
+ */
58
+ open?(url: string, target: string, features: string): unknown;
59
+ /** The browser's word on whether a person pressed something in this frame a moment ago, where it has one. */
60
+ readonly navigator?: { readonly userActivation?: { readonly isActive: boolean } };
54
61
  }
55
62
 
56
63
  /** As much of `document` as the bridge uses. */
@@ -124,9 +131,11 @@ export interface PluginFrame {
124
131
  /** The console's page follows a path of the console's in place; a URL is refused. */
125
132
  navigate(path: string): void;
126
133
  /**
127
- * The console's page opens a web or a mail address in a new tab (ADR-0067), for a link a
128
- * person pressed: call it from the press itself, since the page opens nothing but right after
129
- * one. Anything else, a path of the console's included, is refused; `navigate` takes those.
134
+ * Opens a web or a mail address in a new tab, with no opener and no referrer, for a link a
135
+ * person pressed (ADR-0067, ADR-0078): the browser opens it for a press in the frame and for
136
+ * nothing else, one window a press, so call it from the press itself; without a recent press
137
+ * it is refused, where the browser can say so. Anything else, a path of the console's included,
138
+ * is refused; `navigate` takes those. Needs a console from 0.4.6, whose frames may open a window.
130
139
  */
131
140
  open(url: string): void;
132
141
  /** The console's page downloads a file of this plugin. */
@@ -365,7 +374,15 @@ export function connect(options: ConnectOptions = {}): Promise<PluginFrame> {
365
374
  "open takes a web or a mail address; navigate takes a path of the console's",
366
375
  });
367
376
  }
368
- post({ v: PLUGIN_BRIDGE_VERSION, t: "open", url });
377
+ // The browser holds the frame to a press in it (ADR-0078), and says so where it can.
378
+ if (win.navigator?.userActivation?.isActive === false) {
379
+ throw new PluginBridgeError({
380
+ code: "plugin.forbidden",
381
+ message:
382
+ "open opens a link right after a person pressed in the frame, and not otherwise",
383
+ });
384
+ }
385
+ win.open?.(url, "_blank", "noopener,noreferrer");
369
386
  },
370
387
  download: (id) => post({ v: PLUGIN_BRIDGE_VERSION, t: "download", id }),
371
388
  setTitle: (text) => {