sitespeedio/browsertime

How to fill some text into DOM from nodejs?

kluslulu opened this issue · 4 comments

Your question

image

I want to fill some info into DOM from nodejs,I didn't find any document in https://www.sitespeed.io, only find a simple example using sitespeed.io commands. Could you give me a example how to get DOM(eg:click、addText) in nodejs?

Thanks very much.

Hi @kluslulu here's the documentation for different commands: https://www.sitespeed.io/documentation/sitespeed.io/scripting/

Then you also always run JavaScript directly in the browser using:
https://www.sitespeed.io/documentation/sitespeed.io/scripting/#run-javascript

Best
Peter

Hi @soulgalore, thanks so much for your reply.

I saw these two documents,but they need to be executed through the command line or docker like this: "sitespeed.io login.js http://xxx --multi " or "sitespeed.io --preScript login http://xxx"

I want to use nodejs directly, like this(main.js):


async function run() {
  try {
    const result = await sitespeed.run({
      urls: ["https://xxxx"],  //  「How to login?😊」
      browsertime: {
        iterations: 1,
        connectivity: {
          profile: 'native',
          downstreamKbps: undefined,
          upstreamKbps: undefined,
          latency: undefined,
          engine: 'external'
        },
        browser: 'chrome'
      }
    });
    console.log(result);
  } catch (e) {
    console.error(e);
  }
}

run();

Then, getting the result by executing the node command “node main.js” instead of ‘sitespeed.io xxx’
What should I do for login if I want to use node command?

I try to see the source code, but did not find any solutions:
image

I'm not sure if I describe the problem clearly, my English is so poor😭~
Thanks very much again~

Hi @kluslulu sorry there's no good example for that in the documentation. It should be something like this:

const path = require('path');

 const result = await sitespeed.run({
      urls: [path.resolve('yourscriptingfile.js'), 
      multi: true,
      browsertime: {
     ....

Best
Peter

Hi @soulgalore :thanks for your reply 😊

I tried this and it worked ! This is so helpful to me!

Thanks very much~