-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 1. 去除单例创建实例方式;2. 增加Event、XPathException、prompt的检测处理;3. 其它代码优化
- Loading branch information
1 parent
49a4a2b
commit d5e9ec4
Showing
20 changed files
with
265 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
const sdenv = require('sdenv-extend').sdenv(); | ||
const window = sdenv.memory.sdWindow; | ||
module.exports = (sdenv) => { | ||
const window = sdenv.memory.sdWindow; | ||
|
||
function RTCPeerConnection() { | ||
if (!(this instanceof RTCPeerConnection)) { | ||
throw new TypeError("Uncaught TypeError: Failed to construct 'RTCPeerConnection': Please use the 'new' operator, this DOM object constructor cannot be called as a function."); | ||
function RTCPeerConnection() { | ||
if (!(this instanceof RTCPeerConnection)) { | ||
throw new TypeError("Uncaught TypeError: Failed to construct 'RTCPeerConnection': Please use the 'new' operator, this DOM object constructor cannot be called as a function."); | ||
} | ||
this.createDataChannel = function(...params) { | ||
// window.console.log(`【RTCPeerConnection RTCPeerConnection】调用,参数:${params}`) | ||
} | ||
this.createOffer = function(...params) { | ||
// window.console.log(`【RTCPeerConnection createOffer】调用,参数:${params}`) | ||
} | ||
} | ||
this.createDataChannel = function(...params) { | ||
// window.console.log(`【RTCPeerConnection RTCPeerConnection】调用,参数:${params}`) | ||
} | ||
this.createOffer = function(...params) { | ||
// window.console.log(`【RTCPeerConnection createOffer】调用,参数:${params}`) | ||
} | ||
} | ||
sdenv.tools.setNativeFuncName(RTCPeerConnection, 'RTCPeerConnection'); | ||
sdenv.tools.setNativeObjName(RTCPeerConnection.prototype, 'RTCPeerConnection'); | ||
sdenv.tools.setNativeFuncName(RTCPeerConnection, 'RTCPeerConnection'); | ||
sdenv.tools.setNativeObjName(RTCPeerConnection.prototype, 'RTCPeerConnection'); | ||
|
||
|
||
window.RTCPeerConnection = RTCPeerConnection; | ||
window.RTCPeerConnection = RTCPeerConnection; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,39 @@ | ||
const sdenv = require('sdenv-extend').sdenv(); | ||
|
||
sdenv.memory.sdWindow.chrome = { | ||
app: { | ||
isInstalled: false, | ||
InstallState: { | ||
DISABLED: "disabled", | ||
INSTALLED: "installed", | ||
NOT_INSTALLED: "not_installed", | ||
module.exports = (sdenv) => { | ||
sdenv.memory.sdWindow.chrome = { | ||
app: { | ||
isInstalled: false, | ||
InstallState: { | ||
DISABLED: "disabled", | ||
INSTALLED: "installed", | ||
NOT_INSTALLED: "not_installed", | ||
}, | ||
RunningState: { | ||
CANNOT_RUN: "cannot_run", | ||
READY_TO_RUN: "ready_to_run", | ||
RUNNING: "running", | ||
}, | ||
getDetails: function () {}, | ||
getIsInstalled: function() {}, | ||
installState: function() {}, | ||
runningState: function() {}, | ||
}, | ||
RunningState: { | ||
CANNOT_RUN: "cannot_run", | ||
READY_TO_RUN: "ready_to_run", | ||
RUNNING: "running", | ||
}, | ||
getDetails: function () {}, | ||
getIsInstalled: function() {}, | ||
installState: function() {}, | ||
runningState: function() {}, | ||
}, | ||
csi: function() {}, | ||
loadTimes: function() { | ||
return { | ||
"requestTime": 1700779741.985, | ||
"startLoadTime": 1700779741.985, | ||
"commitLoadTime": 1700779742.021, | ||
"finishDocumentLoadTime": 0, | ||
"finishLoadTime": 0, | ||
"firstPaintTime": 0, | ||
"firstPaintAfterLoadTime": 0, | ||
"navigationType": "Reload", | ||
"wasFetchedViaSpdy": false, | ||
"wasNpnNegotiated": true, | ||
"npnNegotiatedProtocol": "http/1.1", | ||
"wasAlternateProtocolAvailable": false, | ||
"connectionInfo": "http/1.1" | ||
csi: function() {}, | ||
loadTimes: function() { | ||
return { | ||
"requestTime": 1700779741.985, | ||
"startLoadTime": 1700779741.985, | ||
"commitLoadTime": 1700779742.021, | ||
"finishDocumentLoadTime": 0, | ||
"finishLoadTime": 0, | ||
"firstPaintTime": 0, | ||
"firstPaintAfterLoadTime": 0, | ||
"navigationType": "Reload", | ||
"wasFetchedViaSpdy": false, | ||
"wasNpnNegotiated": true, | ||
"npnNegotiatedProtocol": "http/1.1", | ||
"wasAlternateProtocolAvailable": false, | ||
"connectionInfo": "http/1.1" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
const logger = require('@utils/logger'); | ||
const utils = require('sdenv-jsdom/lib/jsdom/living/generated/utils.js'); | ||
const sdenv = require('sdenv-extend').sdenv(); | ||
const window = sdenv.memory.sdWindow; | ||
|
||
const ctorRegistry = window[utils.ctorRegistrySymbol] | ||
window[utils.ctorRegistrySymbol] = new window.Proxy(ctorRegistry, { | ||
get(target, propKey, receiver) { | ||
logger.trace('proxy ctorRegistry get', propKey); | ||
return window.Reflect.get(target, propKey, receiver); | ||
} | ||
}) | ||
module.exports = (sdenv) => { | ||
const window = sdenv.memory.sdWindow; | ||
const ctorRegistry = window[utils.ctorRegistrySymbol] | ||
window[utils.ctorRegistrySymbol] = new window.Proxy(ctorRegistry, { | ||
get(target, propKey, receiver) { | ||
logger.trace('proxy ctorRegistry get', propKey); | ||
return window.Reflect.get(target, propKey, receiver); | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
const utils = require('sdenv-jsdom/lib/jsdom/living/generated/utils.js'); | ||
const sdenv = require('sdenv-extend').sdenv(); | ||
const document = sdenv.memory.sdWindow.document; | ||
|
||
const getElementsByTagNameOri = document.getElementsByTagName; | ||
document.getElementsByTagName = (...params) => { | ||
var findArr = getElementsByTagNameOri.apply(document, params); | ||
if (params[0] === 'script' && document.readyState === 'loading' && document[utils.implSymbol]._currentScript) { | ||
// dom动态解析的临时解决方案,看后续是否会产生其它问题 | ||
const findIdx = [...findArr].indexOf(document[utils.implSymbol]._currentScript[utils.wrapperSymbol]); | ||
if (findIdx > -1) { | ||
return [...findArr].slice(0, findIdx + 1); | ||
module.exports = (sdenv) => { | ||
const document = sdenv.memory.sdWindow.document; | ||
const getElementsByTagNameOri = document.getElementsByTagName; | ||
document.getElementsByTagName = (...params) => { | ||
var findArr = getElementsByTagNameOri.apply(document, params); | ||
if (params[0] === 'script' && document.readyState === 'loading' && document[utils.implSymbol]._currentScript) { | ||
// dom动态解析的临时解决方案,看后续是否会产生其它问题 | ||
const findIdx = [...findArr].indexOf(document[utils.implSymbol]._currentScript[utils.wrapperSymbol]); | ||
if (findIdx > -1) { | ||
return [...findArr].slice(0, findIdx + 1); | ||
} | ||
} | ||
return findArr; | ||
} | ||
return findArr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
const getDocumentAll = require('@/build/Release/documentAll').getDocumentAll; | ||
const sdenv = require('sdenv-extend').sdenv(); | ||
const window = sdenv.memory.sdWindow; | ||
module.exports = (sdenv) => { | ||
const window = sdenv.memory.sdWindow; | ||
|
||
window.document.all = getDocumentAll({ length: 3 }); | ||
window.document.all = getDocumentAll({ length: 3 }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
require('./window'); | ||
require('./document'); | ||
require('./navigation'); | ||
require('./navigator'); | ||
require('./chrome'); | ||
require('./visualViewport'); | ||
require('./styleMedia'); | ||
// require('./webkitRequestFileSystem'); | ||
require('./ctorRegistry'); | ||
require('./location'); | ||
require('./indexedDB'); | ||
require('./RTCPeerConnection'); | ||
require('./document-element'); | ||
module.exports = (sdenv) => { | ||
require('./window')(sdenv); | ||
require('./document')(sdenv); | ||
require('./navigation')(sdenv); | ||
require('./navigator')(sdenv); | ||
require('./chrome')(sdenv); | ||
require('./visualViewport')(sdenv); | ||
require('./styleMedia')(sdenv); | ||
require('./webkitRequestFileSystem')(sdenv); | ||
require('./ctorRegistry')(sdenv); | ||
require('./location')(sdenv); | ||
require('./indexedDB')(sdenv); | ||
require('./RTCPeerConnection')(sdenv); | ||
require('./document-element')(sdenv); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
const sdenv = require('sdenv-extend').sdenv(); | ||
const window = sdenv.memory.sdWindow; | ||
module.exports = (sdenv) => { | ||
const window = sdenv.memory.sdWindow; | ||
|
||
const IDBFactory = function IDBFactory() { | ||
throw new TypeError("Illegal constructor"); | ||
} | ||
const IDBFactory = function IDBFactory() { | ||
throw new TypeError("Illegal constructor"); | ||
} | ||
|
||
const indexedDB = { | ||
__proto__: IDBFactory.prototype | ||
}; | ||
const indexedDB = { | ||
__proto__: IDBFactory.prototype | ||
}; | ||
|
||
sdenv.tools.setNativeFuncName(IDBFactory, 'IDBFactory'); | ||
sdenv.tools.setNativeObjName(indexedDB, 'IDBFactory'); | ||
sdenv.tools.setNativeFuncName(IDBFactory, 'IDBFactory'); | ||
sdenv.tools.setNativeObjName(indexedDB, 'IDBFactory'); | ||
|
||
window.IDBFactory = IDBFactory; | ||
window.indexedDB = indexedDB; | ||
window.IDBFactory = IDBFactory; | ||
window.indexedDB = indexedDB; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
const sdenv = require('sdenv-extend').sdenv(); | ||
const window = sdenv.memory.sdWindow; | ||
module.exports = (sdenv) => { | ||
const window = sdenv.memory.sdWindow; | ||
|
||
Object.defineProperty(window.location, 'replace', { | ||
...Object.getOwnPropertyDescriptor(window.location, 'replace'), | ||
writable: false, | ||
value: function(url) { | ||
sdenv.tools.exit({ url }); | ||
} | ||
}); | ||
Object.defineProperty(window.location, 'replace', { | ||
...Object.getOwnPropertyDescriptor(window.location, 'replace'), | ||
writable: false, | ||
value: function(url) { | ||
sdenv.tools.exit({ url }); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
const sdenv = require('sdenv-extend').sdenv(); | ||
const window = sdenv.memory.sdWindow; | ||
module.exports = (sdenv) => { | ||
const window = sdenv.memory.sdWindow; | ||
|
||
[window.Navigation, window.navigation] = sdenv.tools.getNativeProto('Navigation', 'navigation', { | ||
canGoBack: false, | ||
canGoForward: false, | ||
oncurrententrychange: null, | ||
onnavigate: null, | ||
onnavigateerror: null, | ||
onnavigatesuccess: null, | ||
transition: null, | ||
currentEntry: { | ||
id: 'c72e7c89-2c22-47b6-86b8-e83db973ad22', | ||
index: 1, | ||
key: 'd6cc1590-0028-48e9-b6e7-b489d28d8481', | ||
ondispose: null, | ||
sameDocument: true, | ||
url: 'http://example.com', | ||
} | ||
}); | ||
[window.Navigation, window.navigation] = sdenv.tools.getNativeProto('Navigation', 'navigation', { | ||
canGoBack: false, | ||
canGoForward: false, | ||
oncurrententrychange: null, | ||
onnavigate: null, | ||
onnavigateerror: null, | ||
onnavigatesuccess: null, | ||
transition: null, | ||
currentEntry: { | ||
id: 'c72e7c89-2c22-47b6-86b8-e83db973ad22', | ||
index: 1, | ||
key: 'd6cc1590-0028-48e9-b6e7-b489d28d8481', | ||
ondispose: null, | ||
sameDocument: true, | ||
url: 'http://example.com', | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,49 @@ | ||
const sdenv = require('sdenv-extend').sdenv(); | ||
const window = sdenv.memory.sdWindow; | ||
module.exports = (sdenv) => { | ||
const window = sdenv.memory.sdWindow; | ||
|
||
const DeprecatedStorageQuota = function DeprecatedStorageQuota() { | ||
throw new TypeError("Illegal constructor"); | ||
}; | ||
DeprecatedStorageQuota.prototype = { | ||
queryUsageAndQuota() { | ||
}, | ||
requestQuota() { | ||
}, | ||
}; | ||
sdenv.tools.setObjName(DeprecatedStorageQuota.prototype, "DeprecatedStorageQuota"); | ||
const NetworkInformation = function NetworkInformation() { | ||
throw new TypeError("Illegal constructor"); | ||
} | ||
sdenv.tools.setObjName(NetworkInformation.prototype, "NetworkInformation"); | ||
class NavigatorCustomize { | ||
get webkitPersistentStorage() { | ||
return { __proto__: DeprecatedStorageQuota.prototype }; | ||
} | ||
get connection() { | ||
return { | ||
__proto__: NetworkInformation.prototype, | ||
downlink: 3.85, | ||
effectiveType: "4g", | ||
onchange: null, | ||
rtt: 100, | ||
saveData: false, | ||
}; | ||
} | ||
get userAgent() { | ||
return 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36'; | ||
} | ||
get appVersion() { | ||
return '5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36' | ||
const DeprecatedStorageQuota = function DeprecatedStorageQuota() { | ||
throw new TypeError("Illegal constructor"); | ||
}; | ||
DeprecatedStorageQuota.prototype = { | ||
queryUsageAndQuota() { | ||
}, | ||
requestQuota() { | ||
}, | ||
}; | ||
sdenv.tools.setObjName(DeprecatedStorageQuota.prototype, "DeprecatedStorageQuota"); | ||
const NetworkInformation = function NetworkInformation() { | ||
throw new TypeError("Illegal constructor"); | ||
} | ||
get platform() { | ||
return 'MacIntel'; | ||
} | ||
get vendor() { | ||
return "Google Inc."; | ||
} | ||
}; | ||
sdenv.tools.mixin(window.navigator, NavigatorCustomize.prototype, ['userAgent', 'platform', 'appVersion', 'vendor']); | ||
Object.keys(window.navigator.__proto__).forEach(name => { | ||
sdenv.tools.setFuncNative(Object.getOwnPropertyDescriptor(window.navigator.__proto__, name)?.get, 'get'); | ||
}) | ||
sdenv.tools.setObjName(NetworkInformation.prototype, "NetworkInformation"); | ||
class NavigatorCustomize { | ||
get webkitPersistentStorage() { | ||
return { __proto__: DeprecatedStorageQuota.prototype }; | ||
} | ||
get connection() { | ||
return { | ||
__proto__: NetworkInformation.prototype, | ||
downlink: 3.85, | ||
effectiveType: "4g", | ||
onchange: null, | ||
rtt: 100, | ||
saveData: false, | ||
}; | ||
} | ||
get userAgent() { | ||
return 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36'; | ||
} | ||
get appVersion() { | ||
return '5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36' | ||
} | ||
get platform() { | ||
return 'MacIntel'; | ||
} | ||
get vendor() { | ||
return "Google Inc."; | ||
} | ||
}; | ||
sdenv.tools.mixin(window.navigator, NavigatorCustomize.prototype, ['userAgent', 'platform', 'appVersion', 'vendor']); | ||
Object.keys(window.navigator.__proto__).forEach(name => { | ||
sdenv.tools.setFuncNative(Object.getOwnPropertyDescriptor(window.navigator.__proto__, name)?.get, 'get'); | ||
}) | ||
} |
Oops, something went wrong.