Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] - playwright._impl._api_types.Error: TypeError: undefined is not an object (evaluating 'S[A][m(a[oprand[1]],oprand[1])]') #1012

Open
RyanCCY opened this issue Apr 6, 2023 · 28 comments
Labels
bug Something isn't working

Comments

@RyanCCY
Copy link

RyanCCY commented Apr 6, 2023

Encounters typeerror each time I try running the code.

image

Could I kindly check how to resolve? Thank you.

@RyanCCY RyanCCY added the bug Something isn't working label Apr 6, 2023
@raj199108
Copy link

Same issues with me as well.

Traceback (most recent call last):
File "/home/rajkumar/TikTok-Api/tiktok_test.py", line 16, in
for trending_video in api.trending.videos(count=50):
File "/home/rajkumar/TikTok-Api/TikTokApi/api/trending.py", line 59, in videos
res = Trending.parent.get_data(path, ttwid=ttwid, **kwargs)
File "/home/rajkumar/TikTok-Api/TikTokApi/tiktok.py", line 266, in get_data
) = asyncio.get_event_loop().run_until_complete(
File "/usr/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
return future.result()
File "/home/rajkumar/TikTok-Api/TikTokApi/browser_utilities/browser.py", line 212, in sign_url
evaluatedPage = await page.evaluate(
File "/home/rajkumar/.virtualenvs/tik/lib/python3.9/site-packages/playwright/async_api/_generated.py", line 8590, in evaluate
await self._impl_obj.evaluate(
File "/home/rajkumar/.virtualenvs/tik/lib/python3.9/site-packages/playwright/_impl/_page.py", line 411, in evaluate
return await self._main_frame.evaluate(expression, arg)
File "/home/rajkumar/.virtualenvs/tik/lib/python3.9/site-packages/playwright/_impl/_frame.py", line 277, in evaluate
await self._channel.send(
File "/home/rajkumar/.virtualenvs/tik/lib/python3.9/site-packages/playwright/_impl/_connection.py", line 61, in send
return await self._connection.wrap_api_call(
File "/home/rajkumar/.virtualenvs/tik/lib/python3.9/site-packages/playwright/_impl/_connection.py", line 461, in wrap_api_call
return await cb()
File "/home/rajkumar/.virtualenvs/tik/lib/python3.9/site-packages/playwright/_impl/_connection.py", line 96, in inner_send
result = next(iter(done)).result()
playwright._impl._api_types.Error: TypeError: undefined is not an object (evaluating 'S[A][m(a[oprand[1]],oprand[1])]')

@mristin
Copy link

mristin commented Apr 6, 2023

I observe the same issue.

@max-lychko
Copy link

I have the same

@max-lychko
Copy link

max-lychko commented Apr 6, 2023

Downgrading playwright version to 1.30.0 fixed the issue

@JonahDMonte
Copy link

Downgrading playwright version to 1.30.0 fixed the issue

worked for me too. is there a way to pin this to the top or smth? idk im new to github. ty for your solution mr genius

@RyanCCY
Copy link
Author

RyanCCY commented Apr 9, 2023

Thanks guys! awesome,
managed to downgrade playwright version and seems to be compiling without errors.
However, I can't seem to be generating any results.

image

Would anyone know the solution to this? Or able to paste a sample code for me to run?
Thanks so much once again

@JosephTJennings
Copy link

Same issue; even after the playwright version changes it still occurs.

@lunarforky-z
Copy link

Same issue:

I got same error playwright 1.32

@BigdataCIST
Copy link

Thanks guys! awesome, managed to downgrade playwright version and seems to be compiling without errors. However, I can't seem to be generating any results.

image

Would anyone know the solution to this? Or able to paste a sample code for me to run? Thanks so much once again

Same issue after using playwright 1.3.0

@omar-yehia
Copy link

downgraded but still same error

@lihao189
Copy link

using playwright 1.30.0 solve this problem

@shreyakannan1205
Copy link

I am having the same issue after downgrading to 1.30.0 as well
this is my command for downgrading: python3.8 -m pip install playwright==1.30.0

Screenshot 2023-04-16 at 10 15 03 PM

@JaidenRose
Copy link

I am also encountering this

@Vishdafish126
Copy link

had the same issue with 1.32, got the error, downgraded to 1.30 and compile without issues but don't actually return any results

@dhu16
Copy link

dhu16 commented Apr 18, 2023

same here as well

@Omak2r3a
Copy link

had the same issue with 1.32, got the error, downgraded to 1.30 and compile without issues but don't actually return any results

Check this out

@RayBytes
Copy link

RayBytes commented May 2, 2023

Still having this issue, anyone know the soloution?

@dhu16
Copy link

dhu16 commented May 2, 2023

Still having this issue, anyone know the soloution?

Followed the link @Omak2r3a suggested and got it working

@treksis
Copy link

treksis commented May 25, 2023

same issue

@alvarogomezuria
Copy link

Version 1.34.0 with the same issue

@impuls64s
Copy link

how to solve this problem? code is not working

from TikTokApi import TikTokApi

# Watch https://www.youtube.com/watch?v=-uCt1x8kINQ for a brief setup tutorial
with TikTokApi() as api:
    for trending_video in api.trending.videos(count=50):
        # Prints the author's username of the trending video.
        print(trending_video.author.username)

@reece-barker
Copy link

reece-barker commented Jun 15, 2023

I still have no idea, i am so lost with this. I am running on MacOS gives me the same error despite running different forms and code etc...

Traceback (most recent call last): File "/Users/reece_barker/GitHub/RustNite TikTok/run.py", line 26, in <module> for video in api.trending.videos(): File "/Users/reece_barker/.pyenv/versions/3.10.3/lib/python3.10/site-packages/TikTokApi/api/trending.py", line 59, in videos res = Trending.parent.get_data(path, ttwid=ttwid, **kwargs) File "/Users/reece_barker/.pyenv/versions/3.10.3/lib/python3.10/site-packages/TikTokApi/tiktok.py", line 266, in get_data ) = asyncio.get_event_loop().run_until_complete( File "/Users/reece_barker/.pyenv/versions/3.10.3/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete return future.result() File "/Users/reece_barker/.pyenv/versions/3.10.3/lib/python3.10/site-packages/TikTokApi/browser_utilities/browser.py", line 212, in sign_url evaluatedPage = await page.evaluate( File "/Users/reece_barker/.pyenv/versions/3.10.3/lib/python3.10/site-packages/playwright/async_api/_generated.py", line 8658, in evaluate await self._impl_obj.evaluate( File "/Users/reece_barker/.pyenv/versions/3.10.3/lib/python3.10/site-packages/playwright/_impl/_page.py", line 395, in evaluate return await self._main_frame.evaluate(expression, arg) File "/Users/reece_barker/.pyenv/versions/3.10.3/lib/python3.10/site-packages/playwright/_impl/_frame.py", line 277, in evaluate await self._channel.send( File "/Users/reece_barker/.pyenv/versions/3.10.3/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 61, in send return await self._connection.wrap_api_call( File "/Users/reece_barker/.pyenv/versions/3.10.3/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 482, in wrap_api_call return await cb() File "/Users/reece_barker/.pyenv/versions/3.10.3/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 97, in inner_send result = next(iter(done)).result() playwright._impl._api_types.Error: TypeError: undefined is not an object (evaluating 'S[A][m(a[oprand[1]],oprand[1])]')

my code:

`from TikTokApi import TikTokApi
import json

def get_cookies_from_file():
with open('cookies.json') as f:
cookies = json.load(f)

cookies_kv = {}
for cookie in cookies:
    cookies_kv[cookie['name']] = cookie['value']

return cookies_kv

cookies = get_cookies_from_file()

def get_cookies(**kwargs):
return cookies

api = TikTokApi()

api._get_cookies = get_cookies # This fixes issues the api was having

for video in api.trending.videos():
print(video.author.username)`

@leocunhaO
Copy link

@RyanCCY how were you able to downgrade the playright version to 1.30.0? did you fix the issue?

@incalescence
Copy link

incalescence commented Jun 26, 2023

The steps I took to resolve this issue

  • Remove current version of playright: playwright uninstall --all
  • Install version 1.30.0 of playwright: pip install --force-reinstall -v "playwright==1.30.0"
  • Logged into Tiktok on Chrome and exported my cookies as JSON using EditThisCookie
    image
  • Pasted all cookie data into cookies.json referencing this comment in another issue

Here is the code I had:

from TikTokApi import TikTokApi
import json

def get_cookies_from_file():
    with open('cookies.json') as f:
        cookies = json.load(f)

    cookies_kv = {}
    for cookie in cookies:
        cookies_kv[cookie['name']] = cookie['value']

    return cookies_kv

cookies = get_cookies_from_file()

def get_cookies(**kwargs):
    return cookies

with TikTokApi() as api:
    api._get_cookies = get_cookies
    for trending_video in api.trending.videos(count=10):
        print(trending_video.author.username)

@AlwynHD
Copy link

AlwynHD commented Jun 28, 2023

The steps I took to resolve this issue

  • Remove current version of playright: playwright uninstall --all
  • Install version 1.30.0 of playwright: pip install --force-reinstall -v "playwright==1.30.0"
  • Logged into Tiktok on Chrome and exported my cookies as JSON using EditThisCookie
    image
  • Pasted all cookie data into cookies.json referencing this comment in another issue

Here is the code I had:

from TikTokApi import TikTokApi
import json

def get_cookies_from_file():
    with open('cookies.json') as f:
        cookies = json.load(f)

    cookies_kv = {}
    for cookie in cookies:
        cookies_kv[cookie['name']] = cookie['value']

    return cookies_kv

cookies = get_cookies_from_file()

def get_cookies(**kwargs):
    return cookies

with TikTokApi() as api:
    api._get_cookies = get_cookies
    for trending_video in api.trending.videos(count=10):
        print(trending_video.author.username)

This worked perfectly for me. Thanks :)

@akira9889
Copy link

The steps I took to resolve this issue

The directory structure is as follows:

tiktok
├── cookies.json
├── docker-compose.yml
├── Dockerfile
└── tiktok.py

Dockerfile

FROM mcr.microsoft.com/playwright:v1.30.0-focal

RUN apt-get update && apt-get install -y python3-pip

# Install Playwright and then install the browsers:
RUN pip install --force-reinstall -v "playwright==1.30.0"
RUN playwright install
RUN pip3 install TikTokApi

WORKDIR /app

COPY . .

docker-compose.yml

version: '3.8'
services:
  python-app:
    build: .
    volumes:
      - .:/app
    tty: true

tiktok.py

from TikTokApi import TikTokApi
import json

def get_cookies_from_file():
    with open('./cookies.json') as f:
        cookies = json.load(f)

    cookies_kv = {}
    for cookie in cookies:
        cookies_kv[cookie['name']] = cookie['value']

    return cookies_kv

cookies = get_cookies_from_file()

def get_cookies(**kwargs):
    return cookies

with TikTokApi() as api:
    api._get_cookies = get_cookies
    for trending_video in api.trending.videos(count=10):
        print(trending_video.author.username)

cookies.json

The cookies.json file is exported using the Chrome extension EditThisCookie to get the cookie information from TikTok. (This assumes that you are already logged in to TikTok.)

When you press the export button, it is copied to the clipboard, so you can paste it directly into cookies.json.

Then, by executing the following commands, I was able to retrieve the user.

Check the current directory

pwd

Output ~/tiktok

Enter the container

docker-compose exec python-app bash

Execute the following in the container

root@:/app# python3 tiktok.py

@davidteather
Copy link
Owner

Probably fixed in V6

@davidteather
Copy link
Owner

This is a weird issue, I can't seem to figure it out. But it works if you specify webkit as your browser
If anyone else looks into it, I've found this

user_agent = await session.page.evaluate("() => navigator.userAgent")

this throws the error

user_agent = await session.page.evaluate("() => navigator.userAgentData")

Doesn't, and most other attribute accesses seem to work fine. It feels like a weird way that playwright must've changed handling this in 1.4.0

But this script works normally so it might be an issue on how this library is assigning pages?

import asyncio
from playwright.async_api import async_playwright

async def run():
    async with async_playwright() as playwright:
        browser = await playwright.chromium.launch(headless=True)  # Set headless=True to run without UI
        page = await browser.new_page()
        await page.goto('https://tiktok.com')

        user_agent = await page.evaluate("() => navigator.userAgent")
        print(user_agent)

        await page.wait_for_timeout(5000)  
        await browser.close()

asyncio.run(run())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests