ff-dom 1.0.10 → 1.0.11

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.
@@ -173,11 +173,25 @@ function checkReferenceElementIsValid(locator, relation, tempDiv) {
173
173
  }
174
174
  const getElementsFromHTML = (name, desc, type, locators, isShared, projectId, projectType, isRecorded, folder, parentId, parentName, platform, licenseId, licenseType, userId, htmlString) => {
175
175
  var _a;
176
- const dom = new jsdom_1.JSDOM(htmlString);
176
+ const virtualConsole = new jsdom_1.VirtualConsole();
177
+ const dom = new jsdom_1.JSDOM(htmlString, {
178
+ resources: "usable",
179
+ runScripts: "outside-only", // Prevents inline script execution in JSDOM
180
+ pretendToBeVisual: true,
181
+ virtualConsole,
182
+ includeNodeLocations: true,
183
+ });
177
184
  const document = dom.window.document;
178
185
  global.SVGElement = dom.window.SVGElement;
179
186
  const tempDiv = document.createElement("div");
180
- tempDiv.innerHTML = htmlString;
187
+ const elementsToRemove = document.querySelectorAll("script, style, link[rel='stylesheet'], meta, noscript, embed, object, param, source, svg");
188
+ if (elementsToRemove) {
189
+ elementsToRemove.forEach((tag) => {
190
+ tag.remove();
191
+ });
192
+ }
193
+ tempDiv.innerHTML = document.body.innerHTML;
194
+ // tempDiv.innerHTML = htmlString;
181
195
  let finalLocators = [];
182
196
  locators: for (const locator of locators) {
183
197
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ff-dom",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,4 +1,4 @@
1
- import { JSDOM } from "jsdom";
1
+ import { JSDOM, VirtualConsole } from "jsdom";
2
2
 
3
3
  type ElementDetails = {
4
4
  id?: string | null;
@@ -274,11 +274,30 @@ const getElementsFromHTML = (
274
274
  userId: string,
275
275
  htmlString: string
276
276
  ): ElementDetails | null => {
277
- const dom = new JSDOM(htmlString);
277
+ const virtualConsole = new VirtualConsole();
278
+ const dom = new JSDOM(htmlString, {
279
+ resources: "usable",
280
+ runScripts: "outside-only", // Prevents inline script execution in JSDOM
281
+ pretendToBeVisual: true,
282
+ virtualConsole,
283
+ includeNodeLocations: true,
284
+ });
285
+
278
286
  const document = dom.window.document;
279
287
  global.SVGElement = dom.window.SVGElement;
280
288
  const tempDiv = document.createElement("div");
281
- tempDiv.innerHTML = htmlString;
289
+ const elementsToRemove = document.querySelectorAll(
290
+ "script, style, link[rel='stylesheet'], meta, noscript, embed, object, param, source, svg"
291
+ );
292
+
293
+ if (elementsToRemove) {
294
+ elementsToRemove.forEach((tag) => {
295
+ (tag as Element).remove();
296
+ });
297
+ }
298
+
299
+ tempDiv.innerHTML = document.body.innerHTML;
300
+ // tempDiv.innerHTML = htmlString;
282
301
  let finalLocators = [];
283
302
 
284
303
  locators: for (const locator of locators) {