Skip to content

[BUG] GM_addElement: when parentNode is null or undefined, it should return null directly. #2500

@F9y4ng

Description

@F9y4ng

Problem:

GM_addElement(null, "img", { id: "test1", src: "abc.jpg" });
GM_addElement(void 0, "img", { id: "test1", src: "abc.jpg" });

Both lines of code above insert elements and return element objects. But in fact it shouldn't be like that.

Expected result:

when parentNode is null or undefined, it should return null directly, and dosen't insert the element.

As I have feedback in tampermonkey#2729, because if I want to insert an IMG into an element, but don't get the element correctly (it returns null or undefined), the IMG will be inserted into the current document instead of in the specified element, which is an unintended error.

Environment:

  • OS: Windows
  • Browser: all
  • Violentmonkey Version: all

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions