question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Phantomas v2] Scope seems to be initialized twice

See original GitHub issue

Hi Maciej,

I’m seeing an issue when testing any website with phantomas v2. It looks like the process of injecting scope.js files into the browser is done twice.

Here are two extracts of logs when ran with DEBUG=phantomas:scope:log:

  phantomas:scope:log phantomas page scope initialized +0ms
  phantomas:scope:log spy: attaching to "open" function with results reporting +0ms
  phantomas:scope:log Spying disabled - initializing domComplexity metrics +0ms
  phantomas:scope:log Spying enabled +0ms
  phantomas:scope:log Spying disabled - initializing hidden content analysis +1ms
  phantomas:scope:log Spying enabled +0ms
  phantomas:scope:log domQueries: initializing page scope code +0ms
  phantomas:scope:log spy: attaching to "getElementById" function with results reporting +2ms
  phantomas:scope:log spy: attaching to "getElementsByClassName" function with results reporting +0ms
  
[... and a bit later ...]

  phantomas:scope:log phantomas page scope initialized +324ms
  phantomas:scope:log spy: attaching to "open" function with results reporting +0ms
  phantomas:scope:log Spying disabled - initializing domComplexity metrics +1ms
  phantomas:scope:log Spying enabled +0ms
  phantomas:scope:log Spying disabled - initializing hidden content analysis +0ms
  phantomas:scope:log Spying enabled +0ms
  phantomas:scope:log domQueries: initializing page scope code +0ms
  phantomas:scope:log spy: attaching to "getElementById" function with results reporting +0ms
  phantomas:scope:log spy: attaching to "getElementsByClassName" function with results reporting +2ms

[...]

Maybe I’m wrong, but it looks like the browser starts by opening a blank page. Phantomas injects scope.js in it. Then the real page is open and scope.js is injected a second time.

Side effects: some events such as milestones (domInteractive, domReady, domComplete) are triggered twice. Some reporting functions are called twice too.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
gmetaiscommented, Oct 7, 2020

I’m testing from the node module like this:

File example.js:

const phantomas = require('./lib/index');

const promise = phantomas('https://www.webpagetest.org/', {
    'analyze-css': true,
    'timeout': 60,
    'wait-for-network-idle': true,
    'phone': true
});

promise.
    then(results => {
        console.log('Metrics', results.getMetrics());
        console.log('Offenders', results.getAllOffenders());
    }).
    catch(res => {
        console.error(res);
    });

When launched with this command: DEBUG=phantomas:scope:log node example.js 2>&1 | grep "page scope"

The result is:

$ DEBUG=phantomas:scope:log node example.js 2>&1 | grep "page scope"
2020-10-07T11:28:39.896Z phantomas:scope:log phantomas page scope initialized
2020-10-07T11:28:39.899Z phantomas:scope:log domQueries: initializing page scope code
2020-10-07T11:28:39.901Z phantomas:scope:log domQueries: page scope code initialized
2020-10-07T11:28:43.011Z phantomas:scope:log phantomas page scope initialized
2020-10-07T11:28:43.012Z phantomas:scope:log domQueries: initializing page scope code
2020-10-07T11:28:43.013Z phantomas:scope:log domQueries: page scope code initialized

Note: there is no redirection on this page.

0reactions
macbrecommented, Oct 7, 2020
diff --git a/core/scope.js b/core/scope.js
index 60caa59..4458a45 100644
--- a/core/scope.js
+++ b/core/scope.js
@@ -324,5 +324,5 @@
   phantomas.getDOMPath = getDOMPath;
   phantomas.nodeRunner = nodeRunner;
 
-  phantomas.log("phantomas page scope initialized");
+  phantomas.log("phantomas page scope initialized (is an iframe: %s)", window.parent == window);
 })(window);
$ DEBUG=phantomas:scope:log ./bin/phantomas.js http://0.0.0.0:8888/iframe.html 2>&1 | grep "page scope"
2020-10-07T14:20:47.350Z phantomas:scope:log phantomas page scope initialized for <http://0.0.0.0:8888/iframe.html> (is an iframe: true)
2020-10-07T14:20:47.351Z phantomas:scope:log domQueries: initializing page scope code
2020-10-07T14:20:47.353Z phantomas:scope:log domQueries: page scope code initialized
2020-10-07T14:20:47.373Z phantomas:scope:log phantomas page scope initialized for <http://0.0.0.0:8888/image-scaling.html> (is an iframe: false)
2020-10-07T14:20:47.373Z phantomas:scope:log domQueries: initializing page scope code
2020-10-07T14:20:47.376Z phantomas:scope:log domQueries: page scope code initialized
Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - [Phantomas v2] Scope seems to be initialized twice -
I'm seeing an issue when testing any website with phantomas v2. It looks like the process of injecting scope.js files into the browser...
Read more >
Why are there TWO zero points when sighting in a scope?
Im new to this air rifle thing, How do you get 2 distances from ... By aligning the scope as we did, it...
Read more >
[Solved]-Declaring Same Static Variable Twice in Global Scope-C++
C 2018 6.9.2 2 says: A declaration of an identifier for an object that has file scope without an initializer, and without a...
Read more >
Init method gets called twice in @Viewscoped bean
The problem was this line of code: <p:ajax process="scope" update="schedule, scheduleForm, scheduleFormPG" listener="#{scheduleView.
Read more >
The 10 Most Common Mistakes in C# Programming - Toptal
Common C# Programming Mistake #2: Misunderstanding default values for uninitialized variables. In C#, value types can't be null. By definition, value types ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found