-
Notifications
You must be signed in to change notification settings - Fork 7
Added sample script which uses connectovercdp #31
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
base: main
Are you sure you want to change the base?
Conversation
|
@Ishita-Jinturkar please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
puagarwa
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also add me readMe file with minimal instructions on how customer would use cdp from our service. Follow examples of playwright for guidance and reference.
| try { | ||
| console.log('🔌 Connecting to CDP server...'); | ||
| const browser = await chromium.connectOverCDP('ENTER YOUR CDP WEBSOCKET URL HERE', | ||
| {headers:{'User-Agent': 'Chrome-DevTools-Protocol/1.3'}}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this mandatory ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
This script retrieves the WebSocket URL for a remote browser using Playwright's API, handling environment variables and making asynchronous HTTP requests.
Add example environment configuration for Playwright service.
Added functionality to fetch CDP WebSocket URL from Playwright service and connect to the CDP server using it.
| import { chromium } from 'playwright'; | ||
|
|
||
| const WORKSPACE_ID = process.env.PLAYWRIGHT_SERVICE_WORKSPACE_ID; | ||
| const REGION = process.env.PLAYWRIGHT_SERVICE_REGION; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we keep this consistent with our other examples where we only ask browser regional endpoint and accesstoken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we modify the script for 2 api flow to support this? First call will go to auth
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the above comment , my expectation is that you ask customer to provide same two env variable which we ask endpoint and token and then internally you could parse and get other thing you need
| } | ||
|
|
||
| console.log('🌐 Navigating to Google...'); | ||
| await page.goto('https://google.com'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change this url to playwright.dev
| try { | ||
| console.log('🔍 Fetching CDP WebSocket URL...'); | ||
| const cdpUrl = await getRemoteBrowserWebSocketUrl(); | ||
| console.log('✅ Got WebSocket URL:', cdpUrl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets not log url, make it debug log
samples/cdp-tests/GetCdpUrl.py
Outdated
| @@ -0,0 +1,53 @@ | |||
| import aiohttp | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets remove this and we should add browser-use example here later.
samples/cdp-tests/.env.example
Outdated
| @@ -0,0 +1,11 @@ | |||
| # Playwright Service Configuration | |||
| PLAYWRIGHT_SERVICE_WORKSPACE_ID=eecf0789-aadf-4a86-a4e3-6c61c3c59d67 | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep these blank
| llm = ChatOllama( | ||
| model="llama3.2:3b", | ||
| host="http://localhost:11434" | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we instead use AI foundry hosted model for making this simple to try, add instructions on top how to get model key, etc
something like this
llm = AzureChatOpenAI(
model_name="gpt-35-turbo",
openai_api_key=os.environ["AZURE_OPENAI_API_KEY"],
azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
deployment_name="gpt-35-turbo",
max_tokens=3000,
api_version=os.environ["AZURE_OPENAI_API_VERSION"],
)
|
|
||
| # Create remote browser session | ||
| print("🔌 Creating remote browser session...") | ||
| browser_session = await create_remote_browser_session(ws_url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: we could abstract get url inside create browser session itself
Clear sensitive information from the example environment file.
Refactor to use Azure OpenAI instead of local Ollama LLM for Amazon product search.
Added a sample js script which uses connectovercdp