links about browser

嵌入式浏览器Konqueror的移植和汉化  

http://solution.eccn.com/pdf/qrs_0715217d.pdf  

浏览器架构图 

http://blog.youkuaiyun.com/shaovey/archive/2008/08/22/2814153.aspx  

王国凡的博客(分析webkit) 

http://blog.youkuaiyun.com/sgnaw  

开源浏览器概要设计 

http://www.minigui.org/downloads/SUM-DESIGN-BROWSER-V1.0.pdf  

一种嵌入式浏览器在数字机顶盒中的应用 

http://www.myembed.com/update_path_liqin_t/Upfiles/001/001/2005_10_29/20051029132344.PDF  

交叉编译webkit 

http://ppbabytiger.spaces.live.com/Blog/cns%21549302309A9552BE%21397.entry

手机浏览器的未来

http://blog.youkuaiyun.com/wanghero/archive/2008/12/11/3498103.aspx


import atexit import json import multiprocessing import time import uuid # import browsergym.core # noqa F401 (we register the openended task as a gym environment) import gymnasium as gym import html2text import tenacity from browsergym.utils.obs import flatten_dom_to_str, overlay_som from openhands.core.exceptions import BrowserInitException from openhands.core.logger import openhands_logger as logger from openhands.runtime.browser.base64 import image_to_png_base64_url from openhands.utils.shutdown_listener import should_continue, should_exit from openhands.utils.tenacity_stop import stop_if_should_exit BROWSER_EVAL_GET_GOAL_ACTION = 'GET_EVAL_GOAL' BROWSER_EVAL_GET_REWARDS_ACTION = 'GET_EVAL_REWARDS' class CloudPSSBrowserEnv: def __init__(self, browsergym_eval_env: str | None = None): """ 初始化浏览器环境实例。 Args: browsergym_eval_env (str | None): 用于评估模式的浏览器环境路径。如果提供,则启用评估模式。 属性: html_text_converter: HTML 文本转换器实例。 eval_mode (bool): 标识是否处于评估模式。 eval_dir (str): 评估目录路径。 browsergym_eval_env (str | None): 评估模式下的浏览器环境路径。 browser_side: 浏览器端通信管道。 agent_side: 代理端通信管道。 说明: - 如果 `browsergym_eval_env` 不为 None,则自动启用评估模式。 - 初始化时会设置多进程启动方法为 'spawn',并创建浏览器和代理之间的通信管道。 - 注册 `close` 方法为程序退出时的清理函数。 """ self.html_text_converter = self.get_html_text_converter() self.eval_mode = False self.eval_dir = '' # EVAL only: browsergym_eval_env must be provided for evaluation self.browsergym_eval_env = browsergym_eval_env self.eval_mode = bool(browsergym_eval_env) # Initialize browser environment process multiprocessing.set_start_method('spawn', force=True) self.browser_side, self.agent_side = multiprocessing.Pipe() self.init_browser() atexit.register(self.close) def get_html_text_converter(self) -> html2text.HTML2Text: html_text_converter = html2text.HTML2Text() # ignore links and images html_text_converter.ignore_links = False html_text_converter.ignore_images = True # use alt text for images html_text_converter.images_to_alt = True # disable auto text wrapping html_text_converter.body_width = 0 return html_text_converter @tenacity.retry( wait=tenacity.wait_fixed(1), stop=tenacity.stop_after_attempt(5) | stop_if_should_exit(), retry=tenacity.retry_if_exception_type(BrowserInitException), ) def init_browser(self) -> None: logger.debug('Starting cloudpss browser env...') try: self.process = multiprocessing.Process(target=self.browser_process) self.process.start() except Exception as e: logger.error(f'Failed to start browser process: {e}') raise if not self.check_alive(timeout=200): self.close() raise BrowserInitException('Failed to start browser environment.') def browser_process(self) -> None: if self.eval_mode: assert self.browsergym_eval_env is not None logger.info('Initializing cloudpss browser env for web browsing evaluation.') if not self.browsergym_eval_env.startswith('browsergym/'): self.browsergym_eval_env = 'browsergym/' + self.browsergym_eval_env if 'visualwebarena' in self.browsergym_eval_env: import browsergym.visualwebarena import nltk nltk.download('punkt_tab') elif 'webarena' in self.browsergym_eval_env: import browsergym.webarena # noqa F401 register webarena tasks as gym environments # type: ignore elif 'miniwob' in self.browsergym_eval_env: import browsergym.miniwob # noqa F401 register miniwob tasks as gym environments # type: ignore else: raise ValueError( f'Unsupported browsergym eval env: {self.browsergym_eval_env}' ) env = gym.make(self.browsergym_eval_env, tags_to_mark='all', timeout=100000) else: env = gym.make( 'browsergym/openended', task_kwargs={'start_url': 'about:blank', 'goal': 'PLACEHOLDER_GOAL'}, wait_for_user_message=False, headless=True, disable_env_checker=True, tags_to_mark='all', timeout=100000, pw_context_kwargs={'accept_downloads': True}, pw_chromium_kwargs={'downloads_path': '/workspace/.downloads/'}, ) obs, info = env.reset() logger.info('Successfully called env.reset') # EVAL ONLY: save the goal into file for evaluation self.eval_goal = None self.goal_image_urls = [] self.eval_rewards: list[float] = [] if self.eval_mode: self.eval_goal = obs['goal'] if 'goal_object' in obs: obs['goal_object'] = list(obs['goal_object']) if len(obs['goal_object']) > 0: self.eval_goal = obs['goal_object'][0]['text'] for message in obs['goal_object']: if message['type'] == 'image_url': image_src = message['image_url'] if isinstance(image_src, dict): image_src = image_src['url'] self.goal_image_urls.append(image_src) logger.debug(f'Browsing goal: {self.eval_goal}') logger.info('Browser env started.') while should_continue(): try: if self.browser_side.poll(timeout=0.01): unique_request_id, action_data = self.browser_side.recv() # shutdown the browser environment if unique_request_id == 'SHUTDOWN': logger.debug('SHUTDOWN recv, shutting down browser env...') env.close() return elif unique_request_id == 'IS_ALIVE': self.browser_side.send(('ALIVE', None)) continue # EVAL ONLY: Get evaluation info if action_data['action'] == BROWSER_EVAL_GET_GOAL_ACTION: self.browser_side.send( ( unique_request_id, { 'text_content': self.eval_goal, 'image_content': self.goal_image_urls, }, ) ) continue elif action_data['action'] == BROWSER_EVAL_GET_REWARDS_ACTION: self.browser_side.send( ( unique_request_id, {'text_content': json.dumps(self.eval_rewards)}, ) ) continue action = action_data['action'] obs, reward, terminated, truncated, info = env.step(action) # EVAL ONLY: Save the rewards into file for evaluation if self.eval_mode: self.eval_rewards.append(reward) # type: ignore # add text content of the page html_str = flatten_dom_to_str(obs['dom_object']) obs['text_content'] = self.html_text_converter.handle(html_str) # make observation serializable obs['set_of_marks'] = image_to_png_base64_url( overlay_som( obs['screenshot'], obs.get('extra_element_properties', {}) ), add_data_prefix=True, ) obs['screenshot'] = image_to_png_base64_url( obs['screenshot'], add_data_prefix=True ) obs['active_page_index'] = obs['active_page_index'].item() obs['elapsed_time'] = obs['elapsed_time'].item() self.browser_side.send((unique_request_id, obs)) except KeyboardInterrupt: logger.debug('Browser env process interrupted by user.') try: env.close() except Exception: pass return def step(self, action_str: str, timeout: float = 120) -> dict: """Execute an action in the browser environment and return the observation.""" unique_request_id = str(uuid.uuid4()) self.agent_side.send((unique_request_id, {'action': action_str})) start_time = time.time() while True: if should_exit() or time.time() - start_time > timeout: raise TimeoutError('Browser environment took too long to respond.') if self.agent_side.poll(timeout=0.01): response_id, obs = self.agent_side.recv() if response_id == unique_request_id: return dict(obs) def check_alive(self, timeout: float = 60) -> bool: self.agent_side.send(('IS_ALIVE', None)) if self.agent_side.poll(timeout=timeout): response_id, _ = self.agent_side.recv() if response_id == 'ALIVE': return True logger.debug(f'Browser env is not alive. Response ID: {response_id}') return False def close(self) -> None: if not self.process.is_alive(): return try: self.agent_side.send(('SHUTDOWN', None)) self.process.join(5) # Wait for the process to terminate if self.process.is_alive(): logger.error( 'Browser process did not terminate, forcefully terminating...' ) self.process.terminate() self.process.join(5) # Wait for the process to terminate if self.process.is_alive(): self.process.kill() self.process.join(5) # Wait for the process to terminate self.agent_side.close() self.browser_side.close() except Exception as e: logger.error(f'Encountered an error when closing browser env: {e}') 我希望进行自己的调试怎么修改以上代码?
08-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值