Skip to content

"SyntaxError: Illegal return statement" may happen on sb.cdp.evaluate(expression) #3480

Closed
@mdmintz

Description

@mdmintz

"SyntaxError: Illegal return statement" may happen on sb.cdp.evaluate(expression)


Simple steps to reproduce:

script = (
    f"""
    function getSomeValue() {{
        return '42';
    }}
    return getSomeValue();
    """
)
data = sb.cdp.evaluate(script)

The workaround for now is to remove the final return statement. (Eg. Replace return getSomeValue(); with getSomeValue()):

script = (
    f"""
    function getSomeValue() {{
        return '42';
    }}
    getSomeValue();
    """
)
data = sb.cdp.evaluate(script)

That's because sb.cdp.evaluate(expression) expects a natural expression (with no return).

Metadata

Metadata

Assignees

Labels

UC Mode / CDP ModeUndetected Chromedriver Mode / CDP Modeworkaround existsYou can reach your destination if you do this...

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions