MCPcopy Create free account
hub / github.com/THUDM/AutoWebGLM / process

Method process

webarena/browser_env/processors.py:702–797  ·  view source on GitHub ↗
(self, page: Page, client: CDPSession, context: str)

Source from the content-addressed store, hash-verified

700 return "\n".join(clean_lines)
701
702 def process(self, page: Page, client: CDPSession, context: str) -> str:
703 # get the tab info
704 open_tabs = page.context.pages
705 # try:
706 # tab_titles = [tab.title() for tab in open_tabs]
707 # current_tab_idx = open_tabs.index(page)
708 # for idx in range(len(open_tabs)):
709 # if idx == current_tab_idx:
710 # tab_titles[
711 # idx
712 # ] = f"Tab {idx} (current): {open_tabs[idx].title()}"
713 # else:
714 # tab_titles[idx] = f"Tab {idx}: {open_tabs[idx].title()}"
715 # tab_title_str = " | ".join(tab_titles)
716 # except Exception:
717 # tab_title_str = " | ".join(
718 # ["Tab {idx}" for idx in range(len(open_tabs))]
719 # )
720
721 try:
722 tab_titles = [tab.title() for tab in open_tabs]
723 current_tab_idx = open_tabs.index(page)
724 for idx in range(len(open_tabs)):
725 if idx == current_tab_idx:
726 tab_titles[
727 idx
728 ] = f"{idx+1}. {open_tabs[idx].title()} <-- current tab"
729 else:
730 tab_titles[idx] = f"{idx+1}. {open_tabs[idx].title()}"
731 tab_title_str = "\n".join(tab_titles)
732 except Exception:
733 tab_title_str = "\n".join(
734 [f"{idx+1}. Default" for idx in range(len(open_tabs))]
735 )
736
737
738 try:
739 browser_info = self.fetch_browser_info(page, client)
740 except Exception:
741 page.wait_for_load_state("load", timeout=500)
742 browser_info = self.fetch_browser_info(page, client)
743
744 if self.observation_type == "html":
745 import time
746 stt = time.time()
747 dom_tree = self.fetch_page_html(
748 browser_info,
749 page,
750 client,
751 current_viewport_only=self.current_viewport_only,
752 )
753
754 print('[fetch]', time.time() - stt)
755
756 stt = time.time()
757 raw_html, content, obs_nodes_info, hp = self.parse_my_html(dom_tree)
758 print('[parse]', time.time() - stt)
759

Callers

nothing calls this directly

Calls 6

fetch_browser_infoMethod · 0.95
fetch_page_htmlMethod · 0.95
parse_my_htmlMethod · 0.95

Tested by

no test coverage detected