javascriptmouseevent

How to simulate click properly on "Show more workflows ..." buton on GitHub?


I'm trying to use Tampermonkey user script on Firefox to click "Show more workflows..." in GitHub repositories like this one. But somehow using this code

// ==UserScript==
// @name         GH show all workflows
// @namespace    http://tampermonkey.net/
// @version      2024-10-28
// @description  try to take over the world!
// @author       You
// @match        https://github.com/*/*/actions
// @match        https://github.com/*/*/actions/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=github.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    setTimeout(function () {
        console.log('DEBUG1');
        document.querySelector('div.ActionListItem')?.click();
        console.log('DEBUG2');
    }, 2000);
})();

somehow generates this error and do not show remaining workflows

Uncaught (in promise) TypeError: t.target.closest(...) is null
    showMore nav_list_group_element.js:74
    l bind.js:73
    window["__f__m2u8mn6l.cv"]/</< GH-show-all-workflows.user.js:21
    setTimeout handler*window["__f__m2u8mn6l.cv"]/</< GH-show-all-workflows.user.js:16
    window["__f__m2u8mn6l.cv"]/< GH-show-all-workflows.user.js:24
    Pt actions:10
    window["__f__m2u8mn6l.cv"]/< GH-show-all-workflows.user.js:1
    "__f__m2u8mn6l.cv" GH-show-all-workflows.user.js:1
    Pt actions:10
    r actions:85
    <anonymous> actions:88
    _ actions:22
nav_list_group_element.js:74:32
    showMore nav_list_group_element.js:74
    InterpretGeneratorResume self-hosted:1420
    AsyncFunctionNext self-hosted:807
    (Async: async)
    l bind.js:73
    window["__f__m2u8mn6l.cv"]/</< GH-show-all-workflows.user.js:21
    (Async: setTimeout handler)
    window["__f__m2u8mn6l.cv"]/</< GH-show-all-workflows.user.js:16
    window["__f__m2u8mn6l.cv"]/< GH-show-all-workflows.user.js:24
    Pt actions:10
    window["__f__m2u8mn6l.cv"]/< GH-show-all-workflows.user.js:1
    "__f__m2u8mn6l.cv" GH-show-all-workflows.user.js:1
    Pt actions:10
    r actions:85
    <anonymous> actions:88
    _ actions:22
    Pt content.js:9
    h content.js:64
    d content.js:67
    send content.js:67
    Tn content.js:16
    send content.js:67
    y content.js:62
    is content.js:63
    fo content.js:22
    (Async: setTimeout handler)
    fo content.js:22
    n content.js:2
    Tn content.js:16
    n content.js:1
    fo content.js:22
    is content.js:63
    n content.js:62
    InterpretGeneratorResume self-hosted:1420
    next self-hosted:1341
    Pt content.js:9
    t content.js:10
    e content.js:1
    i content.js:1
    n content.js:1
    n content.js:1
    Pt content.js:9
    t content.js:1
    rs content.js:62
    forEach self-hosted:160
    Pt content.js:9
    t content.js:10
    rs content.js:58
    Ms content.js:77
    ys content.js:77
    Tn content.js:16
    forEach self-hosted:160
    Pt content.js:9
    t content.js:10
    Tn content.js:16
    o content.js:72

Clicking with mouse on same div works without issues. How can I properly simulate click event so it will work same way as normal mouse click?


Solution

  • I think it is the child button of the div.ActionListItem you should actually try to click (It worked for me at least)

    document.querySelector('div.ActionListItem button').click()