Skip to content

Commit 05bddd0

Browse files
解决检查问题
1 parent c66d22d commit 05bddd0

File tree

7 files changed

+199
-146
lines changed

7 files changed

+199
-146
lines changed

pydoll/commands/dom_commands.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,7 @@
6868
GetNodeStackTracesResponse,
6969
GetOuterHTMLResponse,
7070
GetQueryingDescendantForContainerResponse,
71-
GetRelayoutBoundaryResponse,
72-
GetSearchResultsResponse,
73-
GetTopLayerElementsResponse,
7471
MoveToResponse,
75-
PerformSearchResponse,
76-
PushNodeByPathToFrontendResponse,
77-
PushNodesByBackendIdsToFrontendResponse,
7872
QuerySelectorAllResponse,
7973
QuerySelectorResponse,
8074
RequestNodeResponse,

pydoll/connection/connection_handler.py

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -192,32 +192,37 @@ def _is_connection_closed(self) -> bool:
192192
if self._ws_connection is None:
193193
return True
194194

195-
# Try different ways to check connection status for compatibility
196195
try:
197-
# For websockets library (newer versions)
198-
if hasattr(self._ws_connection, 'closed'):
199-
return self._ws_connection.closed
200-
201-
# For ClientConnection or other connection types
202-
if hasattr(self._ws_connection, 'state'):
203-
# Check if state indicates closed
204-
state = self._ws_connection.state
205-
if hasattr(state, 'name'):
206-
return state.name in ('CLOSED', 'CLOSING')
207-
# For numeric states
208-
return state in (3, 4) # Common closed/closing state values
209-
210-
# Fallback: try to access connection state indirectly
211-
if hasattr(self._ws_connection, 'close_code'):
212-
return self._ws_connection.close_code is not None
213-
214-
# Last resort: assume open if we can't determine state
215-
return False
216-
196+
return self._check_connection_state()
217197
except Exception:
218198
# If any error occurs while checking state, assume closed
219199
return True
220200

201+
def _check_connection_state(self) -> bool:
202+
"""Check connection state using various methods for compatibility."""
203+
# For websockets library (newer versions)
204+
if hasattr(self._ws_connection, 'closed'):
205+
return self._ws_connection.closed
206+
207+
# For ClientConnection or other connection types
208+
if hasattr(self._ws_connection, 'state'):
209+
return self._check_state_attribute()
210+
211+
# Fallback: try to access connection state indirectly
212+
if hasattr(self._ws_connection, 'close_code'):
213+
return self._ws_connection.close_code is not None
214+
215+
# Last resort: assume open if we can't determine state
216+
return False
217+
218+
def _check_state_attribute(self) -> bool:
219+
"""Check connection state attribute."""
220+
state = self._ws_connection.state
221+
if hasattr(state, 'name'):
222+
return state.name in {'CLOSED', 'CLOSING'}
223+
# For numeric states
224+
return state in {3, 4} # Common closed/closing state values
225+
221226
async def _receive_events(self):
222227
"""Main loop for receiving and processing WebSocket messages."""
223228
try:

pydoll/fingerprint/browser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ def get_fingerprint_summary(self) -> Optional[dict]:
140140
return self.fingerprint_manager.get_fingerprint_summary()
141141
return None
142142

143-
def _get_default_binary_location(self) -> str:
143+
@staticmethod
144+
def _get_default_binary_location() -> str:
144145
"""Get default Chrome executable path."""
145-
from pydoll.browser.chromium.chrome import Chrome as BaseChrome
146146
return BaseChrome._get_default_binary_location()
147147

148148

@@ -270,7 +270,7 @@ def get_fingerprint_summary(self) -> Optional[dict]:
270270
return self.fingerprint_manager.get_fingerprint_summary()
271271
return None
272272

273-
def _get_default_binary_location(self) -> str:
273+
@staticmethod
274+
def _get_default_binary_location() -> str:
274275
"""Get default Edge executable path."""
275-
from pydoll.browser.chromium.edge import Edge as BaseEdge
276276
return BaseEdge._get_default_binary_location()

pydoll/fingerprint/browser_options.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ def __init__(
3838
"""
3939
super().__init__(options)
4040
self.enable_fingerprint_spoofing = enable_fingerprint_spoofing
41-
self.fingerprint_manager = FingerprintManager(fingerprint_config) if enable_fingerprint_spoofing else None
41+
self.fingerprint_manager = (
42+
FingerprintManager(fingerprint_config)
43+
if enable_fingerprint_spoofing
44+
else None
45+
)
4246

4347
def initialize_options(self) -> ChromiumOptions:
4448
"""

0 commit comments

Comments
 (0)