Skip to content

[Bug]: How do I get the variables, classes, or functions in the JS script injected into the page via add_init_script #2877

Closed
@Fly-Playgroud

Description

@Fly-Playgroud

Version

1.52.0

Steps to reproduce

I have a js fileana.js

var analyzer = function {
  
  this.analyze = function(){
    ……
    let listeners = getEventlisteners(element);
    ……
    }
}


const analyzer = new Analyzer()

1.I injected through page.add_init_script(path=./ana.js) .

2.I tried page.evaluate("analyzer.analyze()") called analyzer.analyze, but failed

  1. I tried to use cdpSession and the call also failed

Is here any solution?

Expected behavior

I called successfully!

Actual behavior

failed!!

Additional context

No response

Environment

- Operating System: [Ubuntu 22.04]
- CPU: [arm64]
- Browser: [All, Chromium, Firefox, WebKit]
- Python Version: [3.12]
- Other info:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions