0

I am trying to use Selenium Webdriver (JavaScript Version) and a Chrome Extension to capture network traffic and look for traffic to a specific pattered url. I'm trying to save the matching traffic to a new variable in the window object to simplify testing later.

I can modify the window following the answer here but for some reason I cannot create a new global variable, so when I open the console and type in "window.testing" after the page load it returns undefined.

Content script code snippet:

window.addEventListener('load', loadEvent => {
    let window = loadEvent.currentTarget;
    //Works as expected
    window.document.title='You changed me!';

    window.testing = {test: '123'};
    testing.customlog = 'You made a custom log!';

    // Console logs as expected
    console.log(testing);

    // Gives error - undefined
    console.log(window.testing);
});
halfer
  • 19,824
  • 17
  • 99
  • 186
av0000
  • 1,917
  • 6
  • 31
  • 51

1 Answers1

2

As HTTP is stateless, every time you load the page it will use the initial values of whatever you set in JavaScript. You can't set a global variable in JS and simply make that value stay after loading the page again.

enter link description here

Community
  • 1
  • 1