@vacantthinker/firefox-addon-framework-easy 2026.528.2339 → 2026.529.759

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 CHANGED
@@ -129,6 +129,9 @@ export async function tabOpRemoveCssCode(tabId, code) { }
129
129
 
130
130
  ### 📄 File: `src/serviceCommon.js`
131
131
  ```javascript
132
+ export async function serviceTakeScreenshot(
133
+ { }
134
+
132
135
  export async function serviceElementPicker(message) { }
133
136
 
134
137
  export async function serviceGetFullPageRectData(message) { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vacantthinker/firefox-addon-framework-easy",
3
- "version": "2026.0528.2339",
3
+ "version": "2026.0529.0759",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
@@ -7,7 +7,59 @@ import {
7
7
  import {browserNotificationCreate} from './browserNotification.js';
8
8
 
9
9
  /**
10
- * will get => {rectData, uniqueSelector,}
10
+ *
11
+ * @param param0
12
+ * @param param0.tabId {number}
13
+ * @param param0.filename {string}
14
+ * @param param0.rect {{
15
+ * x,
16
+ * y,
17
+ * width,
18
+ * height,
19
+ * }}
20
+ * @returns {Promise<void>}
21
+ */
22
+ export async function serviceTakeScreenshot(
23
+ {
24
+ tabId,
25
+ filename,
26
+ rect,
27
+ }) {
28
+
29
+ const tag = 'actTakeScreenshot()';
30
+ console.info(tag, `rect=\n`, rect);
31
+ let dataURI = await browser.tabs.captureTab(tabId, {
32
+ rect: rect,
33
+ });
34
+ let assign = Object.assign(
35
+ {},
36
+ {dataURI, filename},
37
+ );
38
+ await browser.scripting.executeScript({
39
+ target: {tabId},
40
+ args: [assign],
41
+ func: function(message) {
42
+ if (message) {
43
+ let {dataURI, filename} = message;
44
+
45
+ imageDataToLocalFile({dataURI, filename});
46
+
47
+ function imageDataToLocalFile({dataURI, filename}) {
48
+ let a = document.createElement('a');
49
+ a.href = dataURI;
50
+ a.download = filename;
51
+ a.click();
52
+ }
53
+
54
+ // todo end if(message)
55
+ }
56
+ },
57
+ });
58
+
59
+ }
60
+
61
+ /**
62
+ * middle ware, output => {rect, uniqueSelector,}
11
63
  * @param message{{
12
64
  * tabId:number,
13
65
  * act:string
@@ -79,14 +131,16 @@ export async function serviceElementPicker(message) {
79
131
  if (target.id === overlayId) return;
80
132
 
81
133
  // Get exact coordinates of the hovered element
82
- const rect = target.getBoundingClientRect();
134
+ const clientRect = target.getBoundingClientRect();
83
135
 
84
136
  // Move the floating overlay exactly over the target
85
137
  overlay.style.setProperty('display', 'block', 'important');
86
- overlay.style.setProperty('top', `${rect.top}px`, 'important');
87
- overlay.style.setProperty('left', `${rect.left}px`, 'important');
88
- overlay.style.setProperty('width', `${rect.width}px`, 'important');
89
- overlay.style.setProperty('height', `${rect.height}px`, 'important');
138
+ overlay.style.setProperty('top', `${clientRect.top}px`, 'important');
139
+ overlay.style.setProperty('left', `${clientRect.left}px`, 'important');
140
+ overlay.style.setProperty('width', `${clientRect.width}px`,
141
+ 'important');
142
+ overlay.style.setProperty('height', `${clientRect.height}px`,
143
+ 'important');
90
144
 
91
145
  // Change mouse cursor to indicate picking mode
92
146
  document.body.style.setProperty('cursor', 'crosshair', 'important');
@@ -102,21 +156,19 @@ export async function serviceElementPicker(message) {
102
156
  stopPickingMode();
103
157
 
104
158
  // Calculate screenshot coordinates
105
- let rect = target.getBoundingClientRect();
106
- let rectData = {
107
- height: rect.height,
108
- width: rect.width,
109
- x: rect.left + window.scrollX,
110
- y: rect.top + window.scrollY,
159
+ let clientRect = target.getBoundingClientRect();
160
+ let rect = {
161
+ height: clientRect.height,
162
+ width: clientRect.width,
163
+ x: clientRect.left + window.scrollX,
164
+ y: clientRect.top + window.scrollY,
111
165
  };
112
166
 
113
- console.log('Target Selected:', {rectData});
114
-
115
167
  // Assuming 'target' is your clicked element (e.g., from e.target)
116
168
  let messageTakeScreenshot = Object.assign(
117
169
  {}, // Start with a fresh, empty object
118
170
  message, // Put the original message first so it doesn't overwrite your new data
119
- {rectData},
171
+ {rect},
120
172
  {
121
173
  // The guaranteed unique CSS path (e.g., "div#wrap > ul > li:nth-of-type(2)")
122
174
  uniqueSelector: getUniqueSelector(target),
@@ -151,7 +203,7 @@ export async function serviceElementPicker(message) {
151
203
  }
152
204
 
153
205
  /**
154
- * middle ware, output: {rectdata}
206
+ * middle ware, output: {rect}
155
207
  *
156
208
  * @param message{{
157
209
  * tabId:number,
@@ -170,13 +222,13 @@ export async function serviceGetFullPageRectData(message) {
170
222
  let x = 0, y = 0;
171
223
  let width = document.documentElement.scrollWidth;
172
224
  let height = document.documentElement.scrollHeight;
173
- let rectData = {
225
+ let rect = {
174
226
  x, y, width, height,
175
227
  };
176
228
  browser.runtime.sendMessage(Object.assign(
177
229
  {},
178
230
  message,
179
- {rectData},
231
+ {rect},
180
232
  ));
181
233
  // todo end if (message)
182
234
  },