NativeScript / ios-jsc

NativeScript for iOS using JavaScriptCore
http://docs.nativescript.org/runtimes/ios
Apache License 2.0
299 stars 59 forks source link

Chrome Dev Tools Integration #696

Open KristinaKoeva opened 7 years ago

KristinaKoeva commented 7 years ago

Enable the following domains

KristinaKoeva commented 7 years ago

Debugger Domain was implemented with these PRs https://github.com/NativeScript/ios-runtime/pull/693 https://github.com/NativeScript/nativescript-cli/pull/2248

jasssonpet commented 7 years ago

Proof of concept to list CSS files in the resources pane:

__registerDomainDispatcher("CSS",
    class CSSDomainDebugger {
        enable() {
            var bundlePath = NSBundle.mainBundle.bundlePath;
            var cssFilePaths = NSBundle.pathsForResourcesOfTypeInDirectory("css", NSString.pathWithComponents([bundlePath, "app"])); // TODO: Search recursively

            for (var cssFilePath of cssFilePaths) {
                var relativePath = cssFilePath.substring(bundlePath.length);
                __inspectorSendEvent(JSON.stringify({
                    "method": "CSS.styleSheetAdded",
                    "params": {
                        "header": {
                            "styleSheetId": relativePath,
                            "frameId": "NativeScriptMainFrameIdentifier",
                            "sourceURL": "file://" + relativePath,
                            "origin": "regular",
                            "title": "",
                            "disabled": false,
                            "isInline": false,
                            "startLine": 0,
                            "startColumn": 0
                        }
                    }
                }));
            }
        }

        getStyleSheetText(params) {
            var styleSheetId = params.styleSheetId;
            var absolutePath = NSString.pathWithComponents([NSBundle.mainBundle.bundlePath, styleSheetId]);
            return { "text": NSString.stringWithContentsOfFileEncodingError(absolutePath, NSUTF8StringEncoding, null).toString() };
        }
    }
);

ping @pkoleva

pkoleva commented 7 years ago

Related issue https://github.com/NativeScript/ios-runtime/issues/788