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

Incompatible: playwright and Jupyter #202

Closed
maxhumber opened this issue Sep 28, 2020 · 2 comments
Closed

Incompatible: playwright and Jupyter #202

maxhumber opened this issue Sep 28, 2020 · 2 comments

Comments

@maxhumber
Copy link

It seems that playwright is incompatible with a Jupyter workflow...

[1] Input Cell:

from playwright import sync_playwright

playwright = sync_playwright().start()

Error:

---------------------------------------------------------------------------
Error                                     Traceback (most recent call last)
<ipython-input-7-238c5383064b> in <module>
      1 from playwright import sync_playwright
      2 
----> 3 playwright = sync_playwright().start()

~/opt/miniconda3/lib/python3.8/site-packages/playwright/__init__.py in sync_playwright()
     25 
     26 def sync_playwright() -> SyncPlaywrightContextManager:
---> 27     return SyncPlaywrightContextManager()
     28 
     29 

~/opt/miniconda3/lib/python3.8/site-packages/playwright/main.py in __init__(self)
     81 class SyncPlaywrightContextManager:
     82     def __init__(self) -> None:
---> 83         self._connection = run_driver()
     84         self._playwright: SyncPlaywright
     85 

~/opt/miniconda3/lib/python3.8/site-packages/playwright/main.py in run_driver()
     75     loop = asyncio.get_event_loop()
     76     if loop.is_running():
---> 77         raise Error("Can only run one Playwright at a time.")
     78     return loop.run_until_complete(run_driver_async())
     79 

Error: Can only run one Playwright at a time.

Likely caused by the fact that Jupyter also uses the event_loop

Would really love to use Playwright with Jupyter!!

@bubthegreat
Copy link

Similarly, the asyncio equivalent that would lend itself well to the jupyter notebook's usage of event loop doesn't seem to properly import attributes fo the async_playwright() instance:

async_playwright
import asyncio
from playwright import async_playwright
​
async def main():
    async with async_playwright() as p:
        for browser_type in [p.chromium, p.firefox, p.webkit]:
            browser = await browser_type.launch()
            page = await browser.newPage()
            await page.goto('http://whatsmyuseragent.org/')
            await page.screenshot(path=f'example-{browser_type.name}.png')
            await browser.close()
​
​
await main()
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-3-c17ac1e75020> in async-def-wrapper()

<ipython-input-2-dfa9e51be15d> in main()
      3 
      4 async def main():
----> 5     async with async_playwright() as p:
      6         for browser_type in [p.chromium, p.firefox, p.webkit]:
      7             browser = await browser_type.launch()

c:\users\bubth\development\playwright\venv\lib\site-packages\playwright\main.py in __aenter__(self)
    110 
    111     async def __aenter__(self) -> AsyncPlaywright:
--> 112         self._connection = await run_driver_async()
    113         self._connection.run_async()
    114         playwright = AsyncPlaywright(

c:\users\bubth\development\playwright\venv\lib\site-packages\playwright\main.py in run_driver_async()
     43 
     44 async def run_driver_async() -> Connection:
---> 45     package_path = get_file_dirname()
     46     driver_name = compute_driver_name()
     47     driver_executable = package_path / "drivers" / driver_name

c:\users\bubth\development\playwright\venv\lib\site-packages\playwright\path_utils.py in get_file_dirname()
      5 def get_file_dirname() -> Path:
      6     """Returns the callee (`__file__`) directory name"""
----> 7     frame = inspect.stack()[1]
      8     module = inspect.getmodule(frame[0])
      9     assert module

C:\Program Files\Python37\lib\inspect.py in stack(context)
   1511 def stack(context=1):
   1512     """Return a list of records for the stack above the caller's frame."""
-> 1513     return getouterframes(sys._getframe(1), context)
   1514 
   1515 def trace(context=1):

C:\Program Files\Python37\lib\inspect.py in getouterframes(frame, context)
   1488     framelist = []
   1489     while frame:
-> 1490         frameinfo = (frame,) + getframeinfo(frame, context)
   1491         framelist.append(FrameInfo(*frameinfo))
   1492         frame = frame.f_back

C:\Program Files\Python37\lib\inspect.py in getframeinfo(frame, context)
   1462         start = lineno - 1 - context//2
   1463         try:
-> 1464             lines, lnum = findsource(frame)
   1465         except OSError:
   1466             lines = index = None

C:\Program Files\Python37\lib\inspect.py in findsource(object)
    826         pat = re.compile(r'^(\s*def\s)|(\s*async\s+def\s)|(.*(?<!\w)lambda(:|\s))|^(\s*@)')
    827         while lnum > 0:
--> 828             if pat.match(lines[lnum]): break
    829             lnum = lnum - 1
    830         return lines, lnum

IndexError: list index out of range

@mxschmitt
Copy link
Member

Thanks for reporting the issue, we merge this as its a duplicate of #178

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants