scottie1984 / swagger-ui-express

Adds middleware to your express app to serve the Swagger UI bound to your Swagger document. This acts as living documentation for your API hosted from within your app.
MIT License
1.4k stars 225 forks source link

customJS and load window => Dom not fully ready apparently #338

Open foulong opened 1 year ago

foulong commented 1 year ago

Hello,

i wish to custom the title, with image (). I use the option "customJs".

expected : access title element and modify it

obtained : impossible to access title element

It seems to dom is not fully loaded. Below, Js code :

window.addEventListener("load", function () {
    console.log("Window onload event called.");
    /* 
    returns (Q : why "length: 0" ?) :
    .swagger-ui getElementsByClassName 
    HTMLCollection { length: 0 }
    0: <section class="swagger-ui swagger-container" data-reactroot="">​
    1: <div class="swagger-ui">
    length: 2
    */
    console.log(".swagger-ui getElementsByClassName", document.querySelector("#swagger-ui").getElementsByClassName("swagger-ui"));
    /* 
    returns :
    .swagger-ui getElementsByClassName undefined
    */
    console.log(
        ".swagger-ui getElementsByClassName",
        document.querySelector("#swagger-ui").getElementsByClassName("swagger-ui")[0],
    );

    // returns : null
    console.log(document.querySelector("#swagger-ui .info .title"));
});

Thx in advance for your help.

sophie-pan commented 8 months ago

any update ?

d4cho commented 7 months ago

I'm having the same issue.

I'm using customJS in my options.

I can't get any elements using querySelector or getElementBy...