Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support setting files #105

Closed
ebebbington opened this issue Jan 23, 2022 · 4 comments · Fixed by #118
Closed

Support setting files #105

ebebbington opened this issue Jan 23, 2022 · 4 comments · Fixed by #118
Assignees

Comments

@ebebbington
Copy link
Member

Method we need to use: https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-setFileInputFiles

Example impl:

class Element {

  public file(path: string) {
    // TODO :: Check that this is an input and file element
    // ...

    await this.#page.protocol.send("DOM.setInputFiles", {
      files: [path],
      objectId: this.#objectId
    })
  }
  files(paths: string[]) {
    // Same as `file()`, but ensure `multiple` attr is used on the elem
  }
}
@SnoCold
Copy link
Collaborator

SnoCold commented Jan 24, 2022

What I think is, Element class should extend Node class from the prototype.d.ts file... And we should Cast the element returned from querySelector to Node

@SnoCold
Copy link
Collaborator

SnoCold commented Jan 25, 2022

Just found that Node is an interface, so maybe we can implement* Node interface on Element class

export interface Node {
            /**
             * Node identifier that is passed into the rest of the DOM messages as the `nodeId`. Backend
             * will only push node with given `id` once. It is aware of all requested nodes and will only
             * fire DOM events for nodes known to the client.
             */
            nodeId: NodeId;
            /**
             * The id of the parent node if any.
             */
            parentId?: NodeId;
            /**
             * The BackendNodeId for this node.
             */
            backendNodeId: BackendNodeId;
            /**
             * `Node`'s nodeType.
             */
            nodeType: integer;
            /**
             * `Node`'s nodeName.
             */
            nodeName: string;
            /**
             * `Node`'s localName.
             */
            localName: string;
            /**
             * `Node`'s nodeValue.
             */
            nodeValue: string;
            /**
             * Child count for `Container` nodes.
             */
            childNodeCount?: integer;
            /**
             * Child nodes of this node when requested with children.
             */
            children?: Node[];
            /**
             * Attributes of the `Element` node in the form of flat array `[name1, value1, name2, value2]`.
             */
            attributes?: string[];
            /**
             * Document URL that `Document` or `FrameOwner` node points to.
             */
            documentURL?: string;
            /**
             * Base URL that `Document` or `FrameOwner` node uses for URL completion.
             */
            baseURL?: string;
            /**
             * `DocumentType`'s publicId.
             */
            publicId?: string;
            /**
             * `DocumentType`'s systemId.
             */
            systemId?: string;
            /**
             * `DocumentType`'s internalSubset.
             */
            internalSubset?: string;
            /**
             * `Document`'s XML version in case of XML documents.
             */
            xmlVersion?: string;
            /**
             * `Attr`'s name.
             */
            name?: string;
            /**
             * `Attr`'s value.
             */
            value?: string;
            /**
             * Pseudo element type for this node.
             */
            pseudoType?: PseudoType;
            /**
             * Shadow root type.
             */
            shadowRootType?: ShadowRootType;
            /**
             * Frame ID for frame owner elements.
             */
            frameId?: Page.FrameId;
            /**
             * Content document for frame owner elements.
             */
            contentDocument?: Node;
            /**
             * Shadow root list for given element host.
             */
            shadowRoots?: Node[];
            /**
             * Content document fragment for template elements.
             */
            templateContent?: Node;
            /**
             * Pseudo elements associated with this node.
             */
            pseudoElements?: Node[];
            /**
             * Import document for the HTMLImport links.
             */
            importedDocument?: Node;
            /**
             * Distributed nodes for given insertion point.
             */
            distributedNodes?: BackendNode[];
            /**
             * Whether the node is SVG.
             */
            isSVG?: boolean;
        }

@ebebbington
Copy link
Member Author

ebebbington commented Jan 25, 2022

my problem with that is, i don't that think interface should be exposed to the user,and only a handful of those props would be useful to us, and even less would be useful to the user

I just can't see the justification or the benefits to us or the user, the protocol api and interfaces are more lower level than the basic high level api we expose (or at least the browser exposes)

@SnoCold
Copy link
Collaborator

SnoCold commented Jan 25, 2022

You're, right, maybe we just need to add a nodeId field 😅😅, and other hidden fields as necessary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants