diff --git a/.circleci/config.yml b/.circleci/config.yml index 078e934443dd4..0ff0e2f86f069 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -57,6 +57,35 @@ parameters: type: boolean default: false +# Executors +executors: + linux-docker: + parameters: + size: + description: "Docker executor size" + default: 2xlarge+ + type: enum + enum: ["medium", "xlarge", "2xlarge+"] + docker: + - image: electron.azurecr.io/build:6555a80939fb4c3ddf9343b3f140e573f40de225 + resource_class: << parameters.size >> + + macos: + parameters: + size: + description: "macOS executor size" + default: large + type: enum + enum: ["medium", "large"] + macos: + xcode: "12.4.0" + resource_class: << parameters.size >> + + # Electron Runners + apple-silicon: + resource_class: electronjs/macos-arm64 + machine: true + # The config expects the following environment variables to be set: # - "SLACK_WEBHOOK" Slack hook URL to send notifications. # @@ -66,41 +95,6 @@ parameters: # CircleCI docs on variables: # https://circleci.com/docs/2.0/env-vars/ -# Build machines configs. -docker-image: &docker-image - docker: - - image: electron.azurecr.io/build:6555a80939fb4c3ddf9343b3f140e573f40de225 - -machine-linux-medium: &machine-linux-medium - <<: *docker-image - resource_class: medium - -machine-linux-xlarge: &machine-linux-xlarge - <<: *docker-image - resource_class: xlarge - -machine-linux-2xlarge: &machine-linux-2xlarge - <<: *docker-image - resource_class: 2xlarge+ - -machine-mac: &machine-mac - macos: - xcode: "12.2.0" - -machine-mac-large: &machine-mac-large - resource_class: large - macos: - xcode: "12.2.0" - -machine-mac-large-arm: &machine-mac-large-arm - resource_class: large - macos: - xcode: "12.2.0" - -machine-mac-arm64: &machine-mac-arm64 - resource_class: electronjs/macos-arm64 - machine: true - # Build configurations options. env-testing-build: &env-testing-build GN_CONFIG: //electron/build/args/testing.gn @@ -230,6 +224,18 @@ step-maybe-notify-slack-success: &step-maybe-notify-slack-success fi when: on_success +step-maybe-cleanup-arm64-mac: &step-maybe-cleanup-arm64-mac + run: + name: Cleanup after testing + command: | + if [ "$TARGET_ARCH" == "arm64" ] &&[ "`uname`" == "Darwin" ]; then + killall Electron || echo "No Electron processes left running" + killall Safari || echo "No Safari processes left running" + rm -rf ~/Library/Application\ Support/Electron* + rm -rf ~/Library/Application\ Support/electron* + fi + when: always + step-checkout-electron: &step-checkout-electron checkout: path: src/electron @@ -266,7 +272,7 @@ step-gclient-sync: &step-gclient-sync if ! git diff-index --quiet HEAD --; then # There are changes to the patches. Make a git commit with the updated patches git add patches - GIT_COMMITTER_NAME="Electron Bot" GIT_COMMITTER_EMAIL="electron@github.com" git commit -m "update patches" --author="Electron Bot " + GIT_COMMITTER_NAME="PatchUp" GIT_COMMITTER_EMAIL="73610968+patchup[bot]@users.noreply.github.com" git commit -m "chore: update patches" --author="PatchUp <73610968+patchup[bot]@users.noreply.github.com>" # Export it mkdir -p ../../patches git format-patch -1 --stdout --keep-subject --no-stat --full-index > ../../patches/update-patches.patch @@ -313,9 +319,10 @@ step-setup-goma-for-build: &step-setup-goma-for-build npm install mkdir third_party node -e "require('./src/utils/goma.js').downloadAndPrepare({ gomaOneForAll: true })" - node -e "require('./src/utils/goma.js').ensure()" + third_party/goma/goma_ctl.py ensure_start echo 'export GN_GOMA_FILE='`node -e "console.log(require('./src/utils/goma.js').gnFilePath)"` >> $BASH_ENV echo 'export LOCAL_GOMA_DIR='`node -e "console.log(require('./src/utils/goma.js').dir)"` >> $BASH_ENV + echo 'export GOMA_FALLBACK_ON_AUTH_FAILURE=true' >> $BASH_ENV cd .. step-restore-brew-cache: &step-restore-brew-cache @@ -492,6 +499,7 @@ step-gn-check: &step-gn-check gn check out/Default //electron/shell/common/api:mojo # Check the hunspell filenames node electron/script/gen-hunspell-filenames.js --check + node electron/script/gen-libc++-filenames.js --check step-electron-build: &step-electron-build run: @@ -517,12 +525,16 @@ step-electron-build: &step-electron-build ninja -C out/Default electron:electron_mksnapshot_zip -j $NUMBER_OF_NINJA_PROCESSES ninja -C out/Default tools/v8_context_snapshot -j $NUMBER_OF_NINJA_PROCESSES gn desc out/Default v8:run_mksnapshot_default args > out/Default/mksnapshot_args + (cd out/Default; zip mksnapshot.zip mksnapshot_args clang_x64_v8_arm64/gen/v8/embedded.S) + rm -rf out/Default/clang_x64_v8_arm64/gen rm -rf out/Default/clang_x64_v8_arm64/obj + rm -rf out/Default/clang_x64/obj # Regenerate because we just deleted some ninja files gn gen out/Default --args="import(\"$GN_CONFIG\") import(\"$GN_GOMA_FILE\") $GN_EXTRA_ARGS $GN_BUILDFLAG_ARGS" fi - ninja -C out/Default electron -j $NUMBER_OF_NINJA_PROCESSES + NINJA_SUMMARIZE_BUILD=1 autoninja -C out/Default electron -j $NUMBER_OF_NINJA_PROCESSES + cp out/Default/.ninja_log out/electron_ninja_log node electron/script/check-symlinks.js step-native-unittests-build: &step-native-unittests-build @@ -585,26 +597,13 @@ step-electron-dist-build: &step-electron-dist-build fi fi -step-electron-dist-store: &step-electron-dist-store - store_artifacts: - path: src/out/Default/dist.zip - destination: dist.zip - -step-electron-maybe-chromedriver-gn-gen: &step-electron-maybe-chromedriver-gn-gen - run: - name: chromedriver GN gen - command: | - cd src - if [ "$TARGET_ARCH" == "arm" ] || [ "$TARGET_ARCH" == "arm64" ]; then - gn gen out/chromedriver --args="import(\"$GN_CONFIG\") import(\"$GN_GOMA_FILE\") is_component_ffmpeg=false proprietary_codecs=false $GN_EXTRA_ARGS $GN_BUILDFLAG_ARGS" - fi - step-electron-chromedriver-build: &step-electron-chromedriver-build run: name: Build chromedriver.zip command: | cd src if [ "$TARGET_ARCH" == "arm" ] || [ "$TARGET_ARCH" == "arm64" ]; then + gn gen out/chromedriver --args="import(\"$GN_CONFIG\") import(\"$GN_GOMA_FILE\") is_component_ffmpeg=false proprietary_codecs=false $GN_EXTRA_ARGS $GN_BUILDFLAG_ARGS" export CHROMEDRIVER_DIR="out/chromedriver" else export CHROMEDRIVER_DIR="out/Default" @@ -618,11 +617,6 @@ step-electron-chromedriver-build: &step-electron-chromedriver-build cp out/chromedriver/chromedriver.zip out/Default fi -step-electron-chromedriver-store: &step-electron-chromedriver-store - store_artifacts: - path: src/out/Default/chromedriver.zip - destination: chromedriver.zip - step-nodejs-headers-build: &step-nodejs-headers-build run: name: Build Node.js headers @@ -630,16 +624,6 @@ step-nodejs-headers-build: &step-nodejs-headers-build cd src ninja -C out/Default third_party/electron_node:headers -step-nodejs-headers-store: &step-nodejs-headers-store - store_artifacts: - path: src/out/Default/gen/node_headers.tar.gz - destination: node_headers.tar.gz - -step-native-unittests-store: &step-native-unittests-store - store_artifacts: - path: src/out/Default/shell_browser_ui_unittests - destination: shell_browser_ui_unittests - step-electron-publish: &step-electron-publish run: name: Publish Electron Dist @@ -672,6 +656,11 @@ step-persist-data-for-tests: &step-persist-data-for-tests - src/third_party/electron_node - src/third_party/nan - src/cross-arch-snapshots + - src/third_party/llvm-build + - src/build/linux + - src/buildtools/third_party/libc++ + - src/buildtools/third_party/libc++abi + - src/out/Default/obj/buildtools/third_party step-electron-dist-unzip: &step-electron-dist-unzip run: @@ -730,11 +719,6 @@ step-verify-ffmpeg: &step-verify-ffmpeg cd src python electron/script/verify-ffmpeg.py --source-root "$PWD" --build-dir out/Default --ffmpeg-path out/ffmpeg -step-ffmpeg-store: &step-ffmpeg-store - store_artifacts: - path: src/out/ffmpeg/ffmpeg.zip - destination: ffmpeg.zip - step-verify-mksnapshot: &step-verify-mksnapshot run: name: Verify mksnapshot @@ -803,11 +787,6 @@ step-mksnapshot-build: &step-mksnapshot-build (cd out/Default; zip mksnapshot.zip mksnapshot_args gen/v8/embedded.S) fi -step-mksnapshot-store: &step-mksnapshot-store - store_artifacts: - path: src/out/Default/mksnapshot.zip - destination: mksnapshot.zip - step-hunspell-build: &step-hunspell-build run: name: hunspell build @@ -817,10 +796,16 @@ step-hunspell-build: &step-hunspell-build ninja -C out/Default electron:hunspell_dictionaries_zip -j $NUMBER_OF_NINJA_PROCESSES fi -step-hunspell-store: &step-hunspell-store - store_artifacts: - path: src/out/Default/hunspell_dictionaries.zip - destination: hunspell_dictionaries.zip +step-maybe-generate-libcxx: &step-maybe-generate-libcxx + run: + name: maybe generate libcxx + command: | + cd src + if [ "`uname`" == "Linux" ]; then + ninja -C out/Default electron:libcxx_headers_zip -j $NUMBER_OF_NINJA_PROCESSES + ninja -C out/Default electron:libcxxabi_headers_zip -j $NUMBER_OF_NINJA_PROCESSES + ninja -C out/Default electron:libcxx_objects_zip -j $NUMBER_OF_NINJA_PROCESSES + fi step-maybe-generate-breakpad-symbols: &step-maybe-generate-breakpad-symbols run: @@ -840,12 +825,7 @@ step-maybe-zip-symbols: &step-maybe-zip-symbols export BUILD_PATH="$PWD/out/Default" ninja -C out/Default electron:licenses ninja -C out/Default electron:electron_version - electron/script/zip-symbols.py -b $BUILD_PATH - -step-symbols-store: &step-symbols-store - store_artifacts: - path: src/out/Default/symbols.zip - destination: symbols.zip + DELETE_DSYMS_AFTER_ZIP=1 electron/script/zip-symbols.py -b $BUILD_PATH step-maybe-cross-arch-snapshot: &step-maybe-cross-arch-snapshot run: @@ -870,11 +850,6 @@ step-maybe-cross-arch-snapshot: &step-maybe-cross-arch-snapshot cp out/Default-mksnapshot-test/*.bin cross-arch-snapshots fi -step-maybe-cross-arch-snapshot-store: &step-maybe-cross-arch-snapshot-store - store_artifacts: - path: src/cross-arch-snapshots - destination: cross-arch-snapshots - step-maybe-trigger-arm-test: &step-maybe-trigger-arm-test run: name: Trigger an arm test on VSTS if applicable @@ -914,19 +889,6 @@ step-fix-known-hosts-linux: &step-fix-known-hosts-linux ./src/electron/.circleci/fix-known-hosts.sh fi -step-ninja-summary: &step-ninja-summary - run: - name: Print ninja summary - command: | - set +e - set +o pipefail - python depot_tools/post_build_ninja_summary.py -C src/out/Default - -step-ninja-report: &step-ninja-report - store_artifacts: - path: src/out/Default/.ninja_log - destination: ninja_log - # Checkout Steps step-generate-deps-hash: &step-generate-deps-hash run: @@ -1138,49 +1100,6 @@ steps-lint: &steps-lint cd src/electron node script/yarn tsc -p tsconfig.script.json -steps-checkout-and-save-cache: &steps-checkout-and-save-cache - steps: - - *step-checkout-electron - - *step-check-for-doc-only-change - - *step-persist-doc-only-change - - *step-maybe-early-exit-doc-only-change - - *step-depot-tools-get - - *step-depot-tools-add-to-path - - *step-restore-brew-cache - - *step-get-more-space-on-mac - - *step-install-gnutar-on-mac - - - *step-generate-deps-hash - - *step-touch-sync-done - - maybe-restore-portaled-src-cache: - halt-if-successful: true - - *step-maybe-restore-git-cache - - *step-set-git-cache-path - # This sync call only runs if .circle-sync-done is an EMPTY file - - *step-gclient-sync - - store_artifacts: - path: patches - - *step-save-git-cache - # These next few steps reset Electron to the correct commit regardless of which cache was restored - - run: - name: Wipe Electron - command: rm -rf src/electron - - *step-checkout-electron - - *step-run-electron-only-hooks - - *step-generate-deps-hash-cleanly - - *step-mark-sync-done - - *step-minimize-workspace-size-from-checkout - - *step-delete-git-directories - - run: - name: Move src folder to the cross-OS portal - command: | - sudo mkdir -p /var/portal - sudo chown -R $(id -u):$(id -g) /var/portal - mv ./src /var/portal - - *step-save-src-cache - - *step-make-src-cache-marker - - *step-save-src-cache-marker - steps-electron-gn-check: &steps-electron-gn-check steps: - attach_workspace: @@ -1308,16 +1227,16 @@ steps-tests: &steps-tests export LLVM_SYMBOLIZER_PATH=$PWD/third_party/llvm-build/Release+Asserts/bin/llvm-symbolizer export MOCHA_TIMEOUT=180000 echo "Piping output to ASAN_SYMBOLIZE ($ASAN_SYMBOLIZE)" - (cd electron && node script/yarn test --runners=main --trace-uncaught --enable-logging --files $(circleci tests glob spec-main/*-spec.ts | circleci tests split)) 2>&1 | $ASAN_SYMBOLIZE - (cd electron && node script/yarn test --runners=remote --trace-uncaught --enable-logging --files $(circleci tests glob spec/*-spec.js | circleci tests split)) 2>&1 | $ASAN_SYMBOLIZE + (cd electron && node script/yarn test --runners=main --trace-uncaught --enable-logging --files $(circleci tests glob spec-main/*-spec.ts | circleci tests split --split-by=timings)) 2>&1 | $ASAN_SYMBOLIZE + (cd electron && node script/yarn test --runners=remote --trace-uncaught --enable-logging --files $(circleci tests glob spec/*-spec.js | circleci tests split --split-by=timings)) 2>&1 | $ASAN_SYMBOLIZE else if [ "$TARGET_ARCH" == "arm64" ] &&[ "`uname`" == "Darwin" ]; then export ELECTRON_SKIP_NATIVE_MODULE_TESTS=true (cd electron && node script/yarn test --runners=main --trace-uncaught --enable-logging) (cd electron && node script/yarn test --runners=remote --trace-uncaught --enable-logging) else - (cd electron && node script/yarn test --runners=main --trace-uncaught --enable-logging --files $(circleci tests glob spec-main/*-spec.ts | circleci tests split)) - (cd electron && node script/yarn test --runners=remote --trace-uncaught --enable-logging --files $(circleci tests glob spec/*-spec.js | circleci tests split)) + (cd electron && node script/yarn test --runners=main --trace-uncaught --enable-logging --files $(circleci tests glob spec-main/*-spec.ts | circleci tests split --split-by=timings)) + (cd electron && node script/yarn test --runners=remote --trace-uncaught --enable-logging --files $(circleci tests glob spec/*-spec.js | circleci tests split --split-by=timings)) fi fi - run: @@ -1340,6 +1259,8 @@ steps-tests: &steps-tests - *step-maybe-notify-slack-failure + - *step-maybe-cleanup-arm64-mac + steps-test-nan: &steps-test-nan steps: - attach_workspace: @@ -1372,9 +1293,6 @@ steps-test-node: &steps-test-node - store_test_results: path: src/junit -chromium-upgrade-branches: &chromium-upgrade-branches - /chromium\-upgrade\/[0-9]+/ - # Command Aliases commands: maybe-restore-portaled-src-cache: @@ -1407,6 +1325,40 @@ commands: rm -rf src mv /var/portal/src ./ fi + + move_and_store_all_artifacts: + steps: + - run: + name: Move all generated artifacts to upload folder + command: | + rm -rf generated_artifacts + mkdir generated_artifacts + mv_if_exist() { + if [ -f "$1" ] || [ -d "$1" ]; then + echo Storing $1 + mv $1 generated_artifacts + else + echo Skipping $1 - It is not present on disk + fi + } + mv_if_exist src/out/Default/dist.zip + mv_if_exist src/out/Default/shell_browser_ui_unittests + mv_if_exist src/out/Default/gen/node_headers.tar.gz + mv_if_exist src/out/Default/symbols.zip + mv_if_exist src/out/Default/mksnapshot.zip + mv_if_exist src/out/Default/chromedriver.zip + mv_if_exist src/out/ffmpeg/ffmpeg.zip + mv_if_exist src/out/Default/hunspell_dictionaries.zip + mv_if_exist src/cross-arch-snapshots + mv_if_exist src/out/electron_ninja_log + when: always + - store_artifacts: + path: generated_artifacts + destination: ./ + - store_artifacts: + path: generated_artifacts/cross-arch-snapshots + destination: cross-arch-snapshots + checkout-from-cache: steps: - *step-checkout-electron @@ -1445,6 +1397,12 @@ commands: checkout-and-assume-cache: type: boolean default: false + save-git-cache: + type: boolean + default: false + checkout-to-create-src-cache: + type: boolean + default: false build: type: boolean default: true @@ -1486,13 +1444,18 @@ commands: - when: condition: << parameters.restore-src-cache >> steps: - - maybe-restore-portaled-src-cache + - maybe-restore-portaled-src-cache: + halt-if-successful: << parameters.checkout-to-create-src-cache >> - *step-maybe-restore-git-cache - *step-set-git-cache-path # This sync call only runs if .circle-sync-done is an EMPTY file - *step-gclient-sync - store_artifacts: path: patches + - when: + condition: << parameters.save-git-cache >> + steps: + - *step-save-git-cache # These next few steps reset Electron to the correct commit regardless of which cache was restored - run: name: Wipe Electron @@ -1502,6 +1465,7 @@ commands: - *step-generate-deps-hash-cleanly - *step-mark-sync-done - *step-minimize-workspace-size-from-checkout + - *step-delete-git-directories - when: condition: << parameters.persist-checkout >> steps: @@ -1510,6 +1474,18 @@ commands: paths: - depot_tools - src + - when: + condition: << parameters.checkout-to-create-src-cache >> + steps: + - run: + name: Move src folder to the cross-OS portal + command: | + sudo mkdir -p /var/portal + sudo chown -R $(id -u):$(id -g) /var/portal + mv ./src /var/portal + - *step-save-src-cache + - *step-make-src-cache-marker + - *step-save-src-cache-marker - when: condition: << parameters.build >> @@ -1528,32 +1504,23 @@ commands: - *step-restore-out-cache - *step-gn-gen-default - *step-electron-build - - *step-ninja-summary - - *step-ninja-report - *step-maybe-electron-dist-strip - *step-electron-dist-build - - *step-electron-dist-store # Native test targets - *step-native-unittests-build - - *step-native-unittests-store # Node.js headers - *step-nodejs-headers-build - - *step-nodejs-headers-store - *step-show-goma-stats # mksnapshot - *step-mksnapshot-build - - *step-mksnapshot-store - *step-maybe-cross-arch-snapshot - - *step-maybe-cross-arch-snapshot-store # chromedriver - - *step-electron-maybe-chromedriver-gn-gen - *step-electron-chromedriver-build - - *step-electron-chromedriver-store - when: condition: << parameters.build-nonproprietary-ffmpeg >> @@ -1561,11 +1528,9 @@ commands: # ffmpeg - *step-ffmpeg-gn-gen - *step-ffmpeg-build - - *step-ffmpeg-store # hunspell - *step-hunspell-build - - *step-hunspell-store # Save all data needed for a further tests run. - when: @@ -1578,7 +1543,6 @@ commands: steps: - *step-maybe-generate-breakpad-symbols - *step-maybe-zip-symbols - - *step-symbols-store - when: condition: << parameters.build >> @@ -1600,6 +1564,8 @@ commands: steps: - *step-save-out-cache + - move_and_store_all_artifacts + # Trigger tests on arm hardware if needed - *step-maybe-trigger-arm-test @@ -1630,6 +1596,9 @@ commands: condition: << parameters.checkout >> steps: - *step-checkout-electron + - *step-touch-sync-done + - *step-maybe-restore-git-cache + - *step-set-git-cache-path - *step-gclient-sync - *step-delete-git-directories - *step-minimize-workspace-size-from-checkout @@ -1644,57 +1613,57 @@ commands: - *step-maybe-generate-breakpad-symbols - *step-maybe-electron-dist-strip - *step-electron-dist-build - - *step-electron-dist-store - *step-maybe-zip-symbols - - *step-symbols-store # mksnapshot - *step-mksnapshot-build - - *step-mksnapshot-store # chromedriver - - *step-electron-maybe-chromedriver-gn-gen - *step-electron-chromedriver-build - - *step-electron-chromedriver-store # Node.js headers - *step-nodejs-headers-build - - *step-nodejs-headers-store # ffmpeg - *step-ffmpeg-gn-gen - *step-ffmpeg-build - - *step-ffmpeg-store # hunspell - *step-hunspell-build - - *step-hunspell-store + + # libcxx + - *step-maybe-generate-libcxx # typescript defs - *step-maybe-generate-typescript-defs # Publish - - *step-electron-publish + - *step-electron-publish + - move_and_store_all_artifacts # List of all jobs. jobs: # Layer 0: Lint. Standalone. lint: - <<: *machine-linux-medium + executor: + name: linux-docker + size: medium environment: <<: *env-linux-medium <<: *steps-lint ts-compile-doc-change: - <<: *machine-linux-medium + executor: + name: linux-docker + size: medium environment: <<: *env-linux-medium <<: *env-testing-build <<: *steps-electron-ts-compile-for-doc-change # Layer 1: Checkout. - linux-checkout: - <<: *machine-linux-2xlarge + linux-checkout-for-workspace: + executor: linux-docker environment: <<: *env-linux-2xlarge GCLIENT_EXTRA_ARGS: '--custom-var=checkout_arm=True --custom-var=checkout_arm64=True' @@ -1704,10 +1673,9 @@ jobs: build: false checkout: true persist-checkout: true - restore-src-cache: false - linux-checkout-fast: - <<: *machine-linux-2xlarge + linux-make-src-cache: + executor: linux-docker environment: <<: *env-linux-2xlarge GCLIENT_EXTRA_ARGS: '--custom-var=checkout_arm=True --custom-var=checkout_arm64=True' @@ -1716,17 +1684,11 @@ jobs: persist: false build: false checkout: true - persist-checkout: true - - linux-checkout-and-save-cache: - <<: *machine-linux-2xlarge - environment: - <<: *env-linux-2xlarge - GCLIENT_EXTRA_ARGS: '--custom-var=checkout_arm=True --custom-var=checkout_arm64=True' - <<: *steps-checkout-and-save-cache + save-git-cache: true + checkout-to-create-src-cache: true linux-checkout-for-native-tests: - <<: *machine-linux-2xlarge + executor: linux-docker environment: <<: *env-linux-2xlarge GCLIENT_EXTRA_ARGS: '--custom-var=checkout_pyyaml=True' @@ -1738,7 +1700,7 @@ jobs: persist-checkout: true linux-checkout-for-native-tests-with-no-patches: - <<: *machine-linux-2xlarge + executor: linux-docker environment: <<: *env-linux-2xlarge GCLIENT_EXTRA_ARGS: '--custom-var=apply_patches=False --custom-var=checkout_pyyaml=True' @@ -1750,7 +1712,7 @@ jobs: persist-checkout: true mac-checkout: - <<: *machine-linux-2xlarge + executor: linux-docker environment: <<: *env-linux-2xlarge <<: *env-testing-build @@ -1764,8 +1726,8 @@ jobs: persist-checkout: true restore-src-cache: false - mac-checkout-fast: - <<: *machine-linux-2xlarge + mac-checkout-for-workspace: + executor: linux-docker environment: <<: *env-linux-2xlarge <<: *env-testing-build @@ -1778,18 +1740,24 @@ jobs: checkout: true persist-checkout: true - mac-checkout-and-save-cache: - <<: *machine-linux-2xlarge + mac-make-src-cache: + executor: linux-docker environment: <<: *env-linux-2xlarge <<: *env-testing-build <<: *env-macos-build GCLIENT_EXTRA_ARGS: '--custom-var=checkout_mac=True --custom-var=host_os=mac' - <<: *steps-checkout-and-save-cache + steps: + - electron-build: + persist: false + build: false + checkout: true + save-git-cache: true + checkout-to-create-src-cache: true # Layer 2: Builds. linux-x64-testing: - <<: *machine-linux-2xlarge + executor: linux-docker environment: <<: *env-global <<: *env-testing-build @@ -1802,7 +1770,7 @@ jobs: use-out-cache: false linux-x64-testing-asan: - <<: *machine-linux-2xlarge + executor: linux-docker environment: <<: *env-global <<: *env-testing-build @@ -1818,7 +1786,7 @@ jobs: build-nonproprietary-ffmpeg: false linux-x64-testing-no-run-as-node: - <<: *machine-linux-2xlarge + executor: linux-docker environment: <<: *env-linux-2xlarge <<: *env-testing-build @@ -1832,14 +1800,16 @@ jobs: use-out-cache: false linux-x64-testing-gn-check: - <<: *machine-linux-medium + executor: + name: linux-docker + size: medium environment: <<: *env-linux-medium <<: *env-testing-build <<: *steps-electron-gn-check linux-x64-release: - <<: *machine-linux-2xlarge + executor: linux-docker environment: <<: *env-linux-2xlarge-release <<: *env-release-build @@ -1852,7 +1822,7 @@ jobs: checkout: true linux-x64-publish: - <<: *machine-linux-2xlarge + executor: linux-docker environment: <<: *env-linux-2xlarge-release <<: *env-release-build @@ -1863,20 +1833,8 @@ jobs: attach: false checkout: true - linux-x64-publish-skip-checkout: - <<: *machine-linux-2xlarge - environment: - <<: *env-linux-2xlarge-release - <<: *env-release-build - UPLOAD_TO_S3: << pipeline.parameters.upload-to-s3 >> - <<: *env-ninja-status - steps: - - electron-publish: - attach: true - checkout: false - linux-ia32-testing: - <<: *machine-linux-2xlarge + executor: linux-docker environment: <<: *env-global <<: *env-ia32 @@ -1890,7 +1848,7 @@ jobs: use-out-cache: false linux-ia32-release: - <<: *machine-linux-2xlarge + executor: linux-docker environment: <<: *env-linux-2xlarge-release <<: *env-ia32 @@ -1904,7 +1862,7 @@ jobs: checkout: true linux-ia32-publish: - <<: *machine-linux-2xlarge + executor: linux-docker environment: <<: *env-linux-2xlarge-release <<: *env-ia32 @@ -1917,22 +1875,8 @@ jobs: attach: false checkout: true - linux-ia32-publish-skip-checkout: - <<: *machine-linux-2xlarge - environment: - <<: *env-linux-2xlarge-release - <<: *env-ia32 - <<: *env-release-build - <<: *env-32bit-release - UPLOAD_TO_S3: << pipeline.parameters.upload-to-s3 >> - <<: *env-ninja-status - steps: - - electron-publish: - attach: true - checkout: false - linux-arm-testing: - <<: *machine-linux-2xlarge + executor: linux-docker environment: <<: *env-global <<: *env-arm @@ -1948,7 +1892,7 @@ jobs: use-out-cache: false linux-arm-release: - <<: *machine-linux-2xlarge + executor: linux-docker environment: <<: *env-linux-2xlarge-release <<: *env-arm @@ -1962,7 +1906,7 @@ jobs: checkout: true linux-arm-publish: - <<: *machine-linux-2xlarge + executor: linux-docker environment: <<: *env-linux-2xlarge-release <<: *env-arm @@ -1976,22 +1920,8 @@ jobs: attach: false checkout: true - linux-arm-publish-skip-checkout: - <<: *machine-linux-2xlarge - environment: - <<: *env-linux-2xlarge-release - <<: *env-arm - <<: *env-release-build - <<: *env-32bit-release - UPLOAD_TO_S3: << pipeline.parameters.upload-to-s3 >> - <<: *env-ninja-status - steps: - - electron-publish: - attach: true - checkout: false - linux-arm64-testing: - <<: *machine-linux-2xlarge + executor: linux-docker environment: <<: *env-global <<: *env-arm64 @@ -2007,7 +1937,9 @@ jobs: use-out-cache: false linux-arm64-testing-gn-check: - <<: *machine-linux-medium + executor: + name: linux-docker + size: medium environment: <<: *env-linux-medium <<: *env-arm64 @@ -2015,7 +1947,7 @@ jobs: <<: *steps-electron-gn-check linux-arm64-release: - <<: *machine-linux-2xlarge + executor: linux-docker environment: <<: *env-linux-2xlarge-release <<: *env-arm64 @@ -2029,7 +1961,7 @@ jobs: checkout: true linux-arm64-publish: - <<: *machine-linux-2xlarge + executor: linux-docker environment: <<: *env-linux-2xlarge-release <<: *env-arm64 @@ -2042,21 +1974,8 @@ jobs: attach: false checkout: true - linux-arm64-publish-skip-checkout: - <<: *machine-linux-2xlarge - environment: - <<: *env-linux-2xlarge-release - <<: *env-arm64 - <<: *env-release-build - UPLOAD_TO_S3: << pipeline.parameters.upload-to-s3 >> - <<: *env-ninja-status - steps: - - electron-publish: - attach: true - checkout: false - osx-testing-x64: - <<: *machine-mac-large + executor: macos environment: <<: *env-mac-large <<: *env-testing-build @@ -2071,28 +1990,16 @@ jobs: attach: false osx-testing-x64-gn-check: - <<: *machine-mac + executor: + name: macos + size: medium environment: <<: *env-machine-mac <<: *env-testing-build <<: *steps-electron-gn-check - osx-release-x64: - <<: *machine-mac-large - environment: - <<: *env-mac-large - <<: *env-release-build - <<: *env-ninja-status - GCLIENT_EXTRA_ARGS: '--custom-var=checkout_mac=True --custom-var=host_os=mac' - steps: - - electron-build: - persist: true - checkout: false - checkout-and-assume-cache: true - attach: false - osx-publish-x64: - <<: *machine-mac-large + executor: macos environment: <<: *env-mac-large-release <<: *env-release-build @@ -2104,7 +2011,7 @@ jobs: checkout: true osx-publish-arm64: - <<: *machine-mac-large-arm + executor: macos environment: <<: *env-mac-large-release <<: *env-release-build @@ -2117,7 +2024,7 @@ jobs: checkout: true osx-publish-x64-skip-checkout: - <<: *machine-mac-large + executor: macos environment: <<: *env-mac-large-release <<: *env-release-build @@ -2129,7 +2036,7 @@ jobs: checkout: false osx-publish-arm64-skip-checkout: - <<: *machine-mac-large-arm + executor: macos environment: <<: *env-mac-large-release <<: *env-release-build @@ -2142,7 +2049,7 @@ jobs: checkout: false osx-testing-arm64: - <<: *machine-mac-large-arm + executor: macos environment: <<: *env-mac-large <<: *env-testing-build @@ -2159,7 +2066,7 @@ jobs: attach: false mas-testing-x64: - <<: *machine-mac-large + executor: macos environment: <<: *env-mac-large <<: *env-mas @@ -2175,30 +2082,17 @@ jobs: attach: false mas-testing-x64-gn-check: - <<: *machine-mac + executor: + name: macos + size: medium environment: <<: *env-machine-mac <<: *env-mas <<: *env-testing-build <<: *steps-electron-gn-check - - mas-release: - <<: *machine-mac-large - environment: - <<: *env-mac-large - <<: *env-mas - <<: *env-release-build - <<: *env-ninja-status - GCLIENT_EXTRA_ARGS: '--custom-var=checkout_mac=True --custom-var=host_os=mac' - steps: - - electron-build: - persist: true - checkout: false - checkout-and-assume-cache: true - attach: false mas-publish: - <<: *machine-mac-large + executor: macos environment: <<: *env-mac-large-release <<: *env-mas @@ -2211,7 +2105,7 @@ jobs: checkout: true mas-publish-arm64: - <<: *machine-mac-large-arm + executor: macos environment: <<: *env-mac-large-release <<: *env-mas-apple-silicon @@ -2224,7 +2118,7 @@ jobs: checkout: true mas-publish-x64-skip-checkout: - <<: *machine-mac-large + executor: macos environment: <<: *env-mac-large-release <<: *env-mas @@ -2236,7 +2130,7 @@ jobs: checkout: false mas-publish-arm64-skip-checkout: - <<: *machine-mac-large-arm + executor: macos environment: <<: *env-mac-large-release <<: *env-mas-apple-silicon @@ -2249,7 +2143,7 @@ jobs: checkout: false mas-testing-arm64: - <<: *machine-mac-large-arm + executor: macos environment: <<: *env-mac-large <<: *env-testing-build @@ -2267,7 +2161,7 @@ jobs: # Layer 3: Tests. linux-x64-unittests: - <<: *machine-linux-2xlarge + executor: linux-docker environment: <<: *env-linux-2xlarge <<: *env-unittests @@ -2275,7 +2169,7 @@ jobs: <<: *steps-native-tests linux-x64-disabled-unittests: - <<: *machine-linux-2xlarge + executor: linux-docker environment: <<: *env-linux-2xlarge <<: *env-unittests @@ -2284,7 +2178,7 @@ jobs: <<: *steps-native-tests linux-x64-chromium-unittests: - <<: *machine-linux-2xlarge + executor: linux-docker environment: <<: *env-linux-2xlarge <<: *env-unittests @@ -2293,7 +2187,7 @@ jobs: <<: *steps-native-tests linux-x64-browsertests: - <<: *machine-linux-2xlarge + executor: linux-docker environment: <<: *env-linux-2xlarge <<: *env-browsertests @@ -2302,7 +2196,9 @@ jobs: <<: *steps-native-tests linux-x64-testing-tests: - <<: *machine-linux-medium + executor: + name: linux-docker + size: medium environment: <<: *env-linux-medium <<: *env-headless-testing @@ -2311,7 +2207,9 @@ jobs: <<: *steps-tests linux-x64-testing-asan-tests: - <<: *machine-linux-medium + executor: + name: linux-docker + size: xlarge environment: <<: *env-linux-medium <<: *env-headless-testing @@ -2322,7 +2220,9 @@ jobs: <<: *steps-tests linux-x64-testing-nan: - <<: *machine-linux-medium + executor: + name: linux-docker + size: medium environment: <<: *env-linux-medium <<: *env-headless-testing @@ -2330,7 +2230,7 @@ jobs: <<: *steps-test-nan linux-x64-testing-node: - <<: *machine-linux-2xlarge + executor: linux-docker environment: <<: *env-linux-medium <<: *env-headless-testing @@ -2338,7 +2238,9 @@ jobs: <<: *steps-test-node linux-x64-release-tests: - <<: *machine-linux-medium + executor: + name: linux-docker + size: medium environment: <<: *env-linux-medium <<: *env-headless-testing @@ -2346,7 +2248,9 @@ jobs: <<: *steps-tests linux-x64-verify-ffmpeg: - <<: *machine-linux-medium + executor: + name: linux-docker + size: medium environment: <<: *env-linux-medium <<: *env-headless-testing @@ -2354,7 +2258,9 @@ jobs: <<: *steps-verify-ffmpeg linux-ia32-testing-tests: - <<: *machine-linux-medium + executor: + name: linux-docker + size: medium environment: <<: *env-linux-medium <<: *env-ia32 @@ -2364,7 +2270,9 @@ jobs: <<: *steps-tests linux-ia32-testing-nan: - <<: *machine-linux-medium + executor: + name: linux-docker + size: medium environment: <<: *env-linux-medium <<: *env-ia32 @@ -2373,7 +2281,7 @@ jobs: <<: *steps-test-nan linux-ia32-testing-node: - <<: *machine-linux-2xlarge + executor: linux-docker environment: <<: *env-linux-medium <<: *env-ia32 @@ -2382,7 +2290,9 @@ jobs: <<: *steps-test-node linux-ia32-release-tests: - <<: *machine-linux-medium + executor: + name: linux-docker + size: medium environment: <<: *env-linux-medium <<: *env-ia32 @@ -2391,7 +2301,9 @@ jobs: <<: *steps-tests linux-ia32-verify-ffmpeg: - <<: *machine-linux-medium + executor: + name: linux-docker + size: medium environment: <<: *env-linux-medium <<: *env-ia32 @@ -2400,30 +2312,17 @@ jobs: <<: *steps-verify-ffmpeg osx-testing-x64-tests: - <<: *machine-mac-large + executor: + name: macos + size: medium environment: <<: *env-mac-large <<: *env-stack-dumping parallelism: 2 <<: *steps-tests - osx-release-x64-tests: - <<: *machine-mac-large - environment: - <<: *env-mac-large - <<: *env-stack-dumping - <<: *env-send-slack-notifications - <<: *steps-tests - - osx-verify-ffmpeg: - <<: *machine-mac - environment: - <<: *env-machine-mac - <<: *env-send-slack-notifications - <<: *steps-verify-ffmpeg - osx-testing-arm64-tests: - <<: *machine-mac-arm64 + executor: apple-silicon environment: <<: *env-mac-large <<: *env-stack-dumping @@ -2431,30 +2330,17 @@ jobs: <<: *steps-tests mas-testing-x64-tests: - <<: *machine-mac-large + executor: + name: macos + size: medium environment: <<: *env-mac-large <<: *env-stack-dumping parallelism: 2 <<: *steps-tests - mas-release-tests: - <<: *machine-mac-large - environment: - <<: *env-mac-large - <<: *env-stack-dumping - <<: *env-send-slack-notifications - <<: *steps-tests - - mas-verify-ffmpeg: - <<: *machine-mac - environment: - <<: *env-machine-mac - <<: *env-send-slack-notifications - <<: *steps-verify-ffmpeg - mas-testing-arm64-tests: - <<: *machine-mac-arm64 + executor: apple-silicon environment: <<: *env-mac-large <<: *env-stack-dumping @@ -2462,54 +2348,16 @@ jobs: <<: *steps-tests # Layer 4: Summary. - linux-x64-release-summary: - <<: *machine-linux-medium + linux-release-summary: + executor: + name: linux-docker + size: medium environment: <<: *env-linux-medium <<: *env-send-slack-notifications steps: - *step-maybe-notify-slack-success - linux-ia32-release-summary: - <<: *machine-linux-medium - environment: - <<: *env-linux-medium - <<: *env-send-slack-notifications - steps: - - *step-maybe-notify-slack-success - - linux-arm-release-summary: - <<: *machine-linux-medium - environment: - <<: *env-linux-medium - <<: *env-send-slack-notifications - steps: - - *step-maybe-notify-slack-success - - linux-arm64-release-summary: - <<: *machine-linux-medium - environment: - <<: *env-linux-medium - <<: *env-send-slack-notifications - steps: - - *step-maybe-notify-slack-success - - mas-release-summary: - <<: *machine-mac - environment: - <<: *env-machine-mac - <<: *env-send-slack-notifications - steps: - - *step-maybe-notify-slack-success - - osx-release-x64-summary: - <<: *machine-mac - environment: - <<: *env-machine-mac - <<: *env-send-slack-notifications - steps: - - *step-maybe-notify-slack-success - workflows: version: 2.1 @@ -2522,22 +2370,13 @@ workflows: publish-linux: when: << pipeline.parameters.run-linux-publish >> jobs: - - linux-checkout - - linux-x64-publish-skip-checkout: - requires: - - linux-checkout + - linux-x64-publish: context: release-env - - linux-ia32-publish-skip-checkout: - requires: - - linux-checkout + - linux-ia32-publish: context: release-env - - linux-arm-publish-skip-checkout: - requires: - - linux-checkout + - linux-arm-publish: context: release-env - - linux-arm64-publish-skip-checkout: - requires: - - linux-checkout + - linux-arm64-publish: context: release-env publish-x64-linux: @@ -2586,7 +2425,7 @@ workflows: when: << pipeline.parameters.run-mas-publish-arm64 >> jobs: - mas-publish-arm64: - context: release-env + context: release-env publish-macos: when: << pipeline.parameters.run-macos-publish >> @@ -2595,15 +2434,19 @@ workflows: - osx-publish-x64-skip-checkout: requires: - mac-checkout + context: release-env - mas-publish-x64-skip-checkout: requires: - mac-checkout + context: release-env - osx-publish-arm64-skip-checkout: requires: - mac-checkout + context: release-env - mas-publish-arm64-skip-checkout: requires: - mac-checkout + context: release-env lint: when: << pipeline.parameters.run-lint >> @@ -2613,15 +2456,15 @@ workflows: build-linux: when: << pipeline.parameters.run-build-linux >> jobs: - - linux-checkout-fast - - linux-checkout-and-save-cache + - linux-checkout-for-workspace + - linux-make-src-cache - linux-x64-testing - linux-x64-testing-asan - linux-x64-testing-no-run-as-node - linux-x64-testing-gn-check: requires: - - linux-checkout-fast + - linux-checkout-for-workspace - linux-x64-testing-tests: requires: - linux-x64-testing @@ -2651,22 +2494,22 @@ workflows: - linux-arm64-testing - linux-arm64-testing-gn-check: requires: - - linux-checkout-fast + - linux-checkout-for-workspace - ts-compile-doc-change build-mac: when: << pipeline.parameters.run-build-mac >> jobs: - - mac-checkout-fast - - mac-checkout-and-save-cache + - mac-checkout-for-workspace + - mac-make-src-cache - osx-testing-x64: requires: - - mac-checkout-and-save-cache + - mac-make-src-cache - osx-testing-x64-gn-check: requires: - - mac-checkout-fast + - mac-checkout-for-workspace - osx-testing-x64-tests: requires: @@ -2674,7 +2517,7 @@ workflows: - osx-testing-arm64: requires: - - mac-checkout-and-save-cache + - mac-make-src-cache - osx-testing-arm64-tests: filters: @@ -2686,11 +2529,11 @@ workflows: - mas-testing-x64: requires: - - mac-checkout-and-save-cache + - mac-make-src-cache - mas-testing-x64-gn-check: requires: - - mac-checkout-fast + - mac-checkout-for-workspace - mas-testing-x64-tests: requires: @@ -2698,7 +2541,7 @@ workflows: - mas-testing-arm64: requires: - - mac-checkout-and-save-cache + - mac-make-src-cache - mas-testing-arm64-tests: filters: @@ -2716,10 +2559,9 @@ workflows: branches: only: - master - - *chromium-upgrade-branches jobs: - - linux-checkout-fast - - linux-checkout-and-save-cache + - linux-checkout-for-workspace + - linux-make-src-cache - linux-x64-release - linux-x64-release-tests: @@ -2728,7 +2570,8 @@ workflows: - linux-x64-verify-ffmpeg: requires: - linux-x64-release - - linux-x64-release-summary: + - linux-release-summary: + name: linux-x64-release-summary requires: - linux-x64-release - linux-x64-release-tests @@ -2741,65 +2584,25 @@ workflows: - linux-ia32-verify-ffmpeg: requires: - linux-ia32-release - - linux-ia32-release-summary: + - linux-release-summary: + name: linux-ia32-release-summary requires: - linux-ia32-release - linux-ia32-release-tests - linux-ia32-verify-ffmpeg - linux-arm-release - - linux-arm-release-summary: + - linux-release-summary: + name: linux-arm-release-summary requires: - linux-arm-release - linux-arm64-release - - linux-arm64-release-summary: + - linux-release-summary: + name: linux-arm64-release-summary requires: - linux-arm64-release - nightly-mac-release-test: - triggers: - - schedule: - cron: "0 0 * * *" - filters: - branches: - only: - - master - - *chromium-upgrade-branches - jobs: - - mac-checkout-fast - - mac-checkout-and-save-cache - - - osx-release-x64: - requires: - - mac-checkout-and-save-cache - - osx-release-x64-tests: - requires: - - osx-release-x64 - - osx-verify-ffmpeg: - requires: - - osx-release-x64 - - osx-release-x64-summary: - requires: - - osx-release-x64 - - osx-release-x64-tests - - osx-verify-ffmpeg - - - mas-release: - requires: - - mac-checkout-and-save-cache - - mas-release-tests: - requires: - - mas-release - - mas-verify-ffmpeg: - requires: - - mas-release - - mas-release-summary: - requires: - - mas-release - - mas-release-tests - - mas-verify-ffmpeg - # Various slow and non-essential checks we run only nightly. # Sanitizer jobs should be added here. linux-checks-nightly: @@ -2810,7 +2613,6 @@ workflows: branches: only: - master - - *chromium-upgrade-branches jobs: - linux-checkout-for-native-tests diff --git a/.env.example b/.env.example index eb3df4b6bdf9c..4d218327bd60e 100644 --- a/.env.example +++ b/.env.example @@ -4,4 +4,3 @@ APPVEYOR_CLOUD_TOKEN= CIRCLE_TOKEN= ELECTRON_GITHUB_TOKEN= -VSTS_TOKEN= \ No newline at end of file diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index ab2ac48d731a5..b47ebf611b95e 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -12,10 +12,7 @@ DEPS @electron/wg-upgrades /script/release @electron/wg-releases # Security WG +/lib/browser/devtools.ts @electron/wg-security +/lib/browser/guest-view-manager.ts @electron/wg-security +/lib/browser/guest-window-proxy.ts @electron/wg-security /lib/browser/rpc-server.ts @electron/wg-security - -# Remote Change Disliker -/lib/browser/remote/ @nornagon -/lib/renderer/remote/ @nornagon -/lib/renderer/api/remote.ts @nornagon -/docs/api/remote.md @nornagon diff --git a/.github/ISSUE_TEMPLATE/Bug_report.md b/.github/ISSUE_TEMPLATE/Bug_report.md deleted file mode 100644 index a1a336a131e19..0000000000000 --- a/.github/ISSUE_TEMPLATE/Bug_report.md +++ /dev/null @@ -1,58 +0,0 @@ ---- -name: Bug report -about: Create a report to help us improve Electron - ---- - - - -### Preflight Checklist - - -* [ ] I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/master/CONTRIBUTING.md) for this project. -* [ ] I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/master/CODE_OF_CONDUCT.md) that this project adheres to. -* [ ] I have searched the issue tracker for an issue that matches the one I want to file, without success. - -### Issue Details - -* **Electron Version:** - * -* **Operating System:** - * -* **Last Known Working Electron version:** - * - -### Expected Behavior - - -### Actual Behavior - - -### To Reproduce - - - - - - - - -### Screenshots - - -### Additional Information - diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000000000..4cecfb14f35b6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,77 @@ +name: Bug Report +description: Report an Electron bug +title: "[Bug]: " +labels: "bug :beetle:" +body: +- type: checkboxes + attributes: + label: Preflight Checklist + description: Please ensure you've completed all of the following. + options: + - label: I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/master/CONTRIBUTING.md) for this project. + required: true + - label: I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/master/CODE_OF_CONDUCT.md) that this project adheres to. + required: true + - label: I have searched the [issue tracker](https://www.github.com/electron/electron/issues) for a feature request that matches the one I want to file, without success. + required: true +- type: input + attributes: + label: Electron Version + description: What version of Electron are you using? + placeholder: 12.0.0 + validations: + required: true +- type: dropdown + attributes: + label: What operating system are you using? + options: + - Windows + - macOS + - Ubuntu + - Other Linux + - Other (specify below) + validations: + required: true +- type: input + attributes: + label: Operating System Version + description: What operating system version are you using? On Windows, click Start button > Settings > System > About. On macOS, click the Apple Menu > About This Mac. On Linux, use lsb_release or uname -a. + placeholder: "e.g. Windows 10 version 1909, macOS Catalina 10.15.7, or Ubuntu 20.04" + validations: + required: true +- type: dropdown + attributes: + label: What arch are you using? + options: + - x64 + - ia32 + - arm64 (including Apple Silicon) + - Other (specify below) + validations: + required: true +- type: input + attributes: + label: Last Known Working Electron version + description: What is the last version of Electron this worked in, if applicable? + placeholder: 11.0.0 +- type: textarea + attributes: + label: Expected Behavior + description: A clear and concise description of what you expected to happen. + validations: + required: true +- type: textarea + attributes: + label: Actual Behavior + description: A clear description of what actually happens. + validations: + required: true +- type: input + attributes: + label: Testcase Gist URL + description: If you can reproduce the issue in a standalone test case, please use [Electron Fiddle](https://github.com/electron/fiddle) to create one and to publish it as a [GitHub gist](https://gist.github.com) and put the gist URL here. This is **the best way** to ensure this issue is triaged quickly. + placeholder: https://gist.github.com/... +- type: textarea + attributes: + label: Additional Information + description: If your problem needs further explanation, or if the issue you're seeing cannot be reproduced in a gist, please add more information here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml index 182c8dc9c3948..807685c5fd72d 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yml +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -1,18 +1,19 @@ name: Feature Request -about: Suggest an idea for Electron +description: Suggest an idea for Electron title: "[Feature Request]: " -labels: "enhancement ✨" +labels: "enhancement :sparkles:" body: -- type: textarea +- type: checkboxes attributes: label: Preflight Checklist - description: Please ensure you've completed the following steps by replacing [ ] with [x] - value: | - * [ ] I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/master/CONTRIBUTING.md) for this project. - * [ ] I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/master/CODE_OF_CONDUCT.md) that this project adheres to. - * [ ] I have searched the issue tracker for a feature request that matches the one I want to file, without success. - validations: - required: true + description: Please ensure you've completed all of the following. + options: + - label: I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/master/CONTRIBUTING.md) for this project. + required: true + - label: I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/master/CODE_OF_CONDUCT.md) that this project adheres to. + required: true + - label: I have searched the [issue tracker](https://www.github.com/electron/electron/issues) for a feature request that matches the one I want to file, without success. + required: true - type: textarea attributes: label: Problem Description diff --git a/.github/ISSUE_TEMPLATE/mac_app_store_private_api_rejection.md b/.github/ISSUE_TEMPLATE/mac_app_store_private_api_rejection.md deleted file mode 100644 index cefd5800e2a73..0000000000000 --- a/.github/ISSUE_TEMPLATE/mac_app_store_private_api_rejection.md +++ /dev/null @@ -1,25 +0,0 @@ ---- -name: Mac App Store Private API Rejection -about: Your app was rejected from the Mac App Store for using private API's - ---- - - - -### Preflight Checklist - - -* [ ] I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/master/CONTRIBUTING.md) for this project. -* [ ] I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/master/CODE_OF_CONDUCT.md) that this project adheres to. - -### Issue Details - -* **Electron Version:** - * - -### Rejection Email - - -### Additional Information - diff --git a/.github/ISSUE_TEMPLATE/mac_app_store_private_api_rejection.yml b/.github/ISSUE_TEMPLATE/mac_app_store_private_api_rejection.yml new file mode 100644 index 0000000000000..497816fe33720 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/mac_app_store_private_api_rejection.yml @@ -0,0 +1,30 @@ +name: Report Mac App Store Private API Rejection +description: Your app was rejected from the Mac App Store for using private API's +title: "[MAS Rejection]: " +body: +- type: checkboxes + attributes: + label: Preflight Checklist + description: Please ensure you've completed all of the following. + options: + - label: I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/master/CONTRIBUTING.md) for this project. + required: true + - label: I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/master/CODE_OF_CONDUCT.md) that this project adheres to. + required: true +- type: input + attributes: + label: Electron Version + description: What version of Electron are you using? + placeholder: 12.0.0 + validations: + required: true +- type: textarea + attributes: + label: Rejection Email + description: Paste the contents of your rejection email here, censoring any private information such as app names. + validations: + required: true +- type: textarea + attributes: + label: Additional Information + description: Add any other context about the problem here. diff --git a/.gitignore b/.gitignore index e92abcd0baa27..b47ed4f8ae3b9 100644 --- a/.gitignore +++ b/.gitignore @@ -17,24 +17,6 @@ *.xcodeproj /.idea/ /dist/ -/external_binaries/ -/out/ -/vendor/.gclient -/vendor/debian_jessie_mips64-sysroot/ -/vendor/debian_stretch_amd64-sysroot/ -/vendor/debian_stretch_arm-sysroot/ -/vendor/debian_stretch_arm64-sysroot/ -/vendor/debian_stretch_i386-sysroot/ -/vendor/gcc-4.8.3-d197-n64-loongson/ -/vendor/readme-gcc483-loongson.txt -/vendor/download/ -/vendor/llvm-build/ -/vendor/llvm/ -/vendor/npm/ -/vendor/python_26/ -/vendor/native_mksnapshot -/vendor/LICENSES.chromium.html -/vendor/pyyaml node_modules/ SHASUMS256.txt **/package-lock.json @@ -68,4 +50,6 @@ ts-gen .depshash-target # Used to accelerate builds after sync -patches/mtime-cache.json \ No newline at end of file +patches/mtime-cache.json + +spec/fixtures/logo.png \ No newline at end of file diff --git a/.husky/.gitignore b/.husky/.gitignore new file mode 100644 index 0000000000000..31354ec138999 --- /dev/null +++ b/.husky/.gitignore @@ -0,0 +1 @@ +_ diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 0000000000000..feac116af9ca6 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +npm run precommit \ No newline at end of file diff --git a/.husky/pre-push b/.husky/pre-push new file mode 100755 index 0000000000000..7482fdf10c359 --- /dev/null +++ b/.husky/pre-push @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +npm run prepack diff --git a/BUILD.gn b/BUILD.gn index ed353ff671e7f..583a720845794 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1,6 +1,7 @@ import("//build/config/locales.gni") import("//build/config/ui.gni") import("//build/config/win/manifest.gni") +import("//components/os_crypt/features.gni") import("//components/spellcheck/spellcheck_build_features.gni") import("//content/public/app/mac_helpers.gni") import("//extensions/buildflags/buildflags.gni") @@ -25,6 +26,8 @@ import("electron_paks.gni") import("filenames.auto.gni") import("filenames.gni") import("filenames.hunspell.gni") +import("filenames.libcxx.gni") +import("filenames.libcxxabi.gni") if (is_mac) { import("//build/config/mac/rules.gni") @@ -32,6 +35,10 @@ if (is_mac) { import("//ui/gl/features.gni") import("//v8/gni/v8.gni") import("build/rules.gni") + + assert( + mac_deployment_target == "10.11.0", + "Chromium has updated the mac_deployment_target, please update this assert, update the supported versions documentation (docs/tutorial/support.md) and flag this as a breaking change") } if (is_linux) { @@ -290,7 +297,7 @@ templated_file("electron_version_header") { action("electron_fuses") { script = "build/fuses/build.py" - inputs = [ "build/fuses/fuses.json" ] + inputs = [ "build/fuses/fuses.json5" ] outputs = [ "$target_gen_dir/fuses.h", @@ -329,8 +336,10 @@ source_set("electron_lib") { "//components/network_hints/common:mojo_bindings", "//components/network_hints/renderer", "//components/network_session_configurator/common", + "//components/os_crypt", "//components/pref_registry", "//components/prefs", + "//components/security_state/content", "//components/upload_list", "//components/user_prefs", "//components/viz/host", @@ -437,12 +446,16 @@ source_set("electron_lib") { } if (is_linux) { - deps += [ "//components/crash/content/browser" ] + deps += [ + "//build/config/linux/gtk:gtkprint", + "//components/crash/content/browser", + ] } if (is_mac) { deps += [ "//components/remote_cocoa/app_shim", + "//components/remote_cocoa/browser", "//content/common:mac_helpers", "//ui/accelerated_widget_mac", ] @@ -508,10 +521,6 @@ source_set("electron_lib") { ] if (use_x11) { sources += filenames.lib_sources_linux_x11 - deps += [ - "//ui/gfx/x", - "//ui/gtk/x", - ] } configs += [ ":gio_unix" ] defines += [ @@ -615,6 +624,8 @@ source_set("electron_lib") { sources += [ "shell/browser/printing/print_preview_message_handler.cc", "shell/browser/printing/print_preview_message_handler.h", + "shell/browser/printing/print_view_manager_electron.cc", + "shell/browser/printing/print_view_manager_electron.h", "shell/renderer/printing/print_render_frame_helper_delegate.cc", "shell/renderer/printing/print_render_frame_helper_delegate.h", ] @@ -622,6 +633,9 @@ source_set("electron_lib") { "//chrome/services/printing/public/mojom", "//components/printing/common:mojo_interfaces", ] + if (is_mac) { + deps += [ "//chrome/services/mac_notifications/public/mojom" ] + } } if (enable_electron_extensions) { @@ -672,6 +686,10 @@ source_set("electron_lib") { ] libs += [ "uxtheme.lib" ] } + + if (allow_runtime_configurable_key_storage) { + defines += [ "ALLOW_RUNTIME_CONFIGURABLE_KEY_STORAGE" ] + } } electron_paks("packed_resources") { @@ -1157,11 +1175,6 @@ if (is_mac) { "//build/config/win:delayloads", ] - if (target_cpu == "arm64") { - configs -= [ "//build/config/win:cfi_linker" ] - ldflags += [ "/guard:cf,nolongjmp" ] - } - if (current_cpu == "x86") { # Set the initial stack size to 0.5MiB, instead of the 1.5MiB needed by # Chrome's main thread. This saves significant memory on threads (like @@ -1288,13 +1301,18 @@ template("dist_zip") { "testonly", ]) flatten = false + flatten_relative_to = false if (defined(invoker.flatten)) { flatten = invoker.flatten + if (defined(invoker.flatten_relative_to)) { + flatten_relative_to = invoker.flatten_relative_to + } } args = rebase_path(outputs + [ _runtime_deps_file ], root_build_dir) + [ target_cpu, target_os, "$flatten", + "$flatten_relative_to", ] } } @@ -1385,6 +1403,43 @@ dist_zip("hunspell_dictionaries_zip") { outputs = [ "$root_build_dir/hunspell_dictionaries.zip" ] } +copy("libcxx_headers") { + sources = libcxx_headers + libcxx_licenses + outputs = [ "$target_gen_dir/electron_libcxx_include/{{source_root_relative_dir}}/{{source_file_part}}" ] +} + +dist_zip("libcxx_headers_zip") { + data_deps = [ ":libcxx_headers" ] + flatten = true + flatten_relative_to = rebase_path( + "$target_gen_dir/electron_libcxx_include/buildtools/third_party/libc++/trunk", + "$root_out_dir") + + outputs = [ "$root_build_dir/libcxx_headers.zip" ] +} + +copy("libcxxabi_headers") { + sources = libcxxabi_headers + libcxxabi_licenses + outputs = [ "$target_gen_dir/electron_libcxxabi_include/{{source_root_relative_dir}}/{{source_file_part}}" ] +} + +dist_zip("libcxxabi_headers_zip") { + data_deps = [ ":libcxxabi_headers" ] + flatten = true + flatten_relative_to = rebase_path( + "$target_gen_dir/electron_libcxxabi_include/buildtools/third_party/libc++abi/trunk", + "$root_out_dir") + + outputs = [ "$root_build_dir/libcxxabi_headers.zip" ] +} + +action("libcxx_objects_zip") { + deps = [ "//buildtools/third_party/libc++" ] + script = "build/zip_libcxx.py" + outputs = [ "$root_build_dir/libcxx_objects.zip" ] + args = rebase_path(outputs) +} + group("electron") { public_deps = [ ":electron_app" ] } diff --git a/DEPS b/DEPS index 1d07810b28320..a1143df5e6a3d 100644 --- a/DEPS +++ b/DEPS @@ -14,11 +14,11 @@ gclient_gn_args = [ vars = { 'chromium_version': - '90.0.4415.0', + '92.0.4511.0', 'node_version': - 'v14.16.0', + 'v14.17.0', 'nan_version': - '2c4ee8a32a299eada3cd6e468bbd0a473bfea96d', + 'v2.14.2', 'squirrel.mac_version': 'cdc0729c8bf8576bfef18629186e1e9ecf1b0d9f', @@ -48,6 +48,8 @@ vars = { # It's only needed to parse the native tests configurations. 'checkout_pyyaml': False, + 'use_rts': False, + 'mac_xcode_version': 'default', # To allow running hooks without parsing the DEPS tree @@ -86,7 +88,7 @@ deps = { 'url': (Var("nodejs_git")) + '/node.git@' + (Var("node_version")), 'condition': 'checkout_node and process_deps', }, - 'src/electron/vendor/pyyaml': { + 'src/third_party/pyyaml': { 'url': (Var("yaml_git")) + '/pyyaml.git@' + (Var("pyyaml_version")), 'condition': 'checkout_pyyaml and process_deps', }, diff --git a/ELECTRON_VERSION b/ELECTRON_VERSION index ebf45eab75afb..f26e618dfcf16 100644 --- a/ELECTRON_VERSION +++ b/ELECTRON_VERSION @@ -1 +1 @@ -14.0.0-nightly.20210308 \ No newline at end of file +15.0.0-nightly.20210602 \ No newline at end of file diff --git a/README.md b/README.md index 84646336ed39f..8928f4a26ff9b 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![devDependency Status](https://david-dm.org/electron/electron/dev-status.svg)](https://david-dm.org/electron/electron?type=dev) [![Electron Discord Invite](https://img.shields.io/discord/745037351163527189?color=%237289DA&label=chat&logo=discord&logoColor=white)](https://discord.com/invite/electron) -:memo: Available Translations: 🇨🇳 🇹🇼 🇧🇷 🇪🇸 🇰🇷 🇯🇵 🇷🇺 🇫🇷 🇹🇭 🇳🇱 🇹🇷 🇮🇩 🇺🇦 🇨🇿 🇮🇹 🇵🇱. +:memo: Available Translations: 🇨🇳 🇧🇷 🇪🇸 🇯🇵 🇷🇺 🇫🇷 🇺🇸 🇩🇪. View these docs in other languages at [electron/i18n](https://github.com/electron/i18n/tree/master/content/). The Electron framework lets you write cross-platform desktop applications diff --git a/appveyor.yml b/appveyor.yml index a88c7834b165a..26449fd65c29c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -36,6 +36,7 @@ environment: ELECTRON_ENABLE_STACK_DUMPING: 1 MOCHA_REPORTER: mocha-multi-reporters MOCHA_MULTI_REPORTERS: mocha-appveyor-reporter, tap + GOMA_FALLBACK_ON_AUTH_FAILURE: true notifications: - provider: Webhook url: https://electron-mission-control.herokuapp.com/rest/appveyor-hook diff --git a/build/args/all.gn b/build/args/all.gn index bb5869ec9d6fe..9d4a8474e49d3 100644 --- a/build/args/all.gn +++ b/build/args/all.gn @@ -19,4 +19,17 @@ enable_basic_printing = true angle_enable_vulkan_validation_layers = false dawn_enable_vulkan_validation_layers = false +# This breaks native node modules +libcxx_abi_unstable = false + +# These are disabled because they cause the zip manifest to differ between +# testing and release builds. +# See https://chromium-review.googlesource.com/c/chromium/src/+/2774898. +enable_pseudolocales = false + is_cfi = false + +enable_pak_file_integrity_checks = false + +# Make application name configurable at runtime for cookie crypto +allow_runtime_configurable_key_storage = true diff --git a/build/dump_syms.py b/build/dump_syms.py index a606cb8789e1b..68cea6394bcd1 100644 --- a/build/dump_syms.py +++ b/build/dump_syms.py @@ -39,7 +39,7 @@ def main(dump_syms, binary, out_dir, stamp_file, dsym_file=None): args += ["-g", dsym_file] args += [binary] - symbol_data = subprocess.check_output(args) + symbol_data = subprocess.check_output(args).decode(sys.stdout.encoding) symbol_path = os.path.join(out_dir, get_symbol_path(symbol_data)) mkdir_p(os.path.dirname(symbol_path)) diff --git a/build/fuses/build.py b/build/fuses/build.py index f17c08fdb8451..6c56dceb091df 100755 --- a/build/fuses/build.py +++ b/build/fuses/build.py @@ -49,8 +49,8 @@ } """ -with open(os.path.join(dir_path, "fuses.json"), 'r') as f: - fuse_defaults = json.load(f) +with open(os.path.join(dir_path, "fuses.json5"), 'r') as f: + fuse_defaults = json.loads(''.join(line for line in f.readlines() if not line.strip()[0] == "/")) fuse_version = fuse_defaults['_version'] del fuse_defaults['_version'] diff --git a/build/fuses/fuses.json b/build/fuses/fuses.json5 similarity index 84% rename from build/fuses/fuses.json rename to build/fuses/fuses.json5 index 9ff211adb43e3..dfc518ffa36e7 100644 --- a/build/fuses/fuses.json +++ b/build/fuses/fuses.json5 @@ -2,5 +2,6 @@ "_comment": "Modifying the fuse schema in any breaking way should result in the _version prop being incremented. NEVER remove a fuse or change its meaning, instead mark it as removed with 'r'", "_schema": "0 == off, 1 == on, r == removed fuse", "_version": 1, - "run_as_node": "1" + "run_as_node": "1", + "cookie_encryption": "0" } diff --git a/build/mac/make_locale_dirs.py b/build/mac/make_locale_dirs.py index a75d0735ad127..21b220f7d913b 100644 --- a/build/mac/make_locale_dirs.py +++ b/build/mac/make_locale_dirs.py @@ -8,6 +8,7 @@ # require any direct Cocoa locale support. import os +import errno import sys @@ -16,7 +17,7 @@ def main(args): try: os.makedirs(dirname) except OSError as e: - if e.errno == os.errno.EEXIST: + if e.errno == errno.EEXIST: # It's OK if it already exists pass else: diff --git a/build/npm-run.py b/build/npm-run.py index a786aa5da62d8..77b9f128e5499 100644 --- a/build/npm-run.py +++ b/build/npm-run.py @@ -15,12 +15,6 @@ try: subprocess.check_output(args, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: - print( - "NPM script '" - + sys.argv[2] - + "' failed with code '" - + str(e.returncode) - + "':\n" - + e.output - ) + error_msg = "NPM script '{}' failed with code '{}':\n".format(sys.argv[2], e.returncode) + print(error_msg + e.output.decode('ascii')) sys.exit(e.returncode) diff --git a/build/webpack/webpack.config.base.js b/build/webpack/webpack.config.base.js index b23ffb95e7748..b2393462afc74 100644 --- a/build/webpack/webpack.config.base.js +++ b/build/webpack/webpack.config.base.js @@ -61,13 +61,6 @@ module.exports = ({ ); } - if (defines.ENABLE_REMOTE_MODULE === 'false') { - ignoredModules.push( - '@electron/internal/browser/remote/server', - '@electron/internal/renderer/api/remote' - ); - } - if (defines.ENABLE_VIEWS_API === 'false') { ignoredModules.push( '@electron/internal/browser/api/views/image-view.js' @@ -163,7 +156,7 @@ if ((globalThis.process || binding.process).argv.includes("--profile-electron-in setImmediate: false }, optimization: { - minimize: true, + minimize: env.mode === 'production', minimizer: [ new TerserPlugin({ terserOptions: { diff --git a/build/webpack/webpack.gni b/build/webpack/webpack.gni index f2bddbd5ae2bc..2157cceabe320 100644 --- a/build/webpack/webpack.gni +++ b/build/webpack/webpack.gni @@ -22,6 +22,11 @@ template("webpack_build") { "//electron/typings/internal-electron.d.ts", ] + invoker.inputs + mode = "development" + if (is_official_build) { + mode = "production" + } + args = [ "--config", rebase_path(invoker.config_file), @@ -29,6 +34,7 @@ template("webpack_build") { "--output-path=" + rebase_path(get_path_info(invoker.out_file, "dir")), "--env.buildflags=" + rebase_path("$target_gen_dir/buildflags/buildflags.h"), + "--env.mode=" + mode, ] deps += [ "buildflags" ] diff --git a/build/zip.py b/build/zip.py index 720141712d891..285544aed0b1f 100644 --- a/build/zip.py +++ b/build/zip.py @@ -39,7 +39,8 @@ './crashpad_handler', # Skip because these are outputs that we don't need. 'resources/inspector', - 'gen/third_party/devtools-frontend/src' + 'gen/third_party/devtools-frontend/src', + 'gen/ui/webui' ] def skip_path(dep, dist_zip, target_cpu): @@ -71,7 +72,7 @@ def execute(argv): raise e def main(argv): - dist_zip, runtime_deps, target_cpu, _, flatten_val = argv + dist_zip, runtime_deps, target_cpu, _, flatten_val, flatten_relative_to = argv should_flatten = flatten_val == "true" dist_files = set() with open(runtime_deps) as f: @@ -98,11 +99,18 @@ def main(argv): if basename == 'chrome_sandbox' else dep ) + name_to_write = arcname + if should_flatten: + if flatten_relative_to: + if name_to_write.startswith(flatten_relative_to): + name_to_write = name_to_write[len(flatten_relative_to):] + else: + name_to_write = os.path.basename(arcname) + else: + name_to_write = os.path.basename(arcname) z.write( dep, - os.path.basename(arcname) - if should_flatten - else arcname, + name_to_write, ) if __name__ == '__main__': diff --git a/build/zip_libcxx.py b/build/zip_libcxx.py new file mode 100644 index 0000000000000..5eec83d2261b9 --- /dev/null +++ b/build/zip_libcxx.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python +from __future__ import print_function +import os +import subprocess +import sys +import zipfile + +def execute(argv): + try: + output = subprocess.check_output(argv, stderr=subprocess.STDOUT) + return output + except subprocess.CalledProcessError as e: + print(e.output) + raise e + +def get_object_files(base_path, archive_name): + archive_file = os.path.join(base_path, archive_name) + output = execute(['nm', '-g', archive_file]).decode('ascii') + object_files = set() + lines = output.split("\n") + for line in lines: + if line.startswith(base_path): + object_file = line.split(":")[0] + object_files.add(object_file) + if line.startswith('nm: '): + object_file = line.split(":")[1].lstrip() + object_files.add(object_file) + return list(object_files) + [archive_file] + +def main(argv): + dist_zip, = argv + out_dir = os.path.dirname(dist_zip) + base_path_libcxx = os.path.join(out_dir, 'obj/buildtools/third_party/libc++') + base_path_libcxxabi = os.path.join(out_dir, 'obj/buildtools/third_party/libc++abi') + object_files_libcxx = get_object_files(base_path_libcxx, 'libc++.a') + object_files_libcxxabi = get_object_files(base_path_libcxxabi, 'libc++abi.a') + with zipfile.ZipFile( + dist_zip, 'w', zipfile.ZIP_DEFLATED, allowZip64=True + ) as z: + object_files_libcxx.sort() + for object_file in object_files_libcxx: + z.write(object_file, os.path.relpath(object_file, base_path_libcxx)) + for object_file in object_files_libcxxabi: + z.write(object_file, os.path.relpath(object_file, base_path_libcxxabi)) + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) \ No newline at end of file diff --git a/buildflags/BUILD.gn b/buildflags/BUILD.gn index 9bd2aba0036a6..9cbb8227f5f52 100644 --- a/buildflags/BUILD.gn +++ b/buildflags/BUILD.gn @@ -12,7 +12,6 @@ buildflag_header("buildflags") { "ENABLE_DESKTOP_CAPTURER=$enable_desktop_capturer", "ENABLE_RUN_AS_NODE=$enable_run_as_node", "ENABLE_OSR=$enable_osr", - "ENABLE_REMOTE_MODULE=$enable_remote_module", "ENABLE_VIEWS_API=$enable_views_api", "ENABLE_PDF_VIEWER=$enable_pdf_viewer", "ENABLE_TTS=$enable_tts", diff --git a/buildflags/buildflags.gni b/buildflags/buildflags.gni index 95de99fe0a339..5adc739ef7bb1 100644 --- a/buildflags/buildflags.gni +++ b/buildflags/buildflags.gni @@ -10,8 +10,6 @@ declare_args() { enable_osr = true - enable_remote_module = true - enable_views_api = true enable_pdf_viewer = true diff --git a/chromium_src/BUILD.gn b/chromium_src/BUILD.gn index 4fdd2a0ead9bf..14d287db3d095 100644 --- a/chromium_src/BUILD.gn +++ b/chromium_src/BUILD.gn @@ -2,6 +2,7 @@ # Use of this source code is governed by the MIT license that can be # found in the LICENSE file. +import("//build/config/ozone.gni") import("//build/config/ui.gni") import("//components/spellcheck/spellcheck_build_features.gni") import("//electron/buildflags/buildflags.gni") @@ -42,9 +43,6 @@ static_library("chrome") { "//chrome/browser/predictors/proxy_lookup_client_impl.h", "//chrome/browser/predictors/resolve_host_client_impl.cc", "//chrome/browser/predictors/resolve_host_client_impl.h", - "//chrome/browser/ssl/security_state_tab_helper.cc", - "//chrome/browser/ssl/security_state_tab_helper.h", - "//chrome/browser/ssl/tls_deprecation_config.cc", "//chrome/browser/ui/views/autofill/autofill_popup_view_utils.cc", "//chrome/browser/ui/views/autofill/autofill_popup_view_utils.h", "//extensions/browser/app_window/size_constraints.cc", @@ -80,7 +78,6 @@ static_library("chrome") { "//components/keyed_service/content", "//components/paint_preview/buildflags", "//components/proxy_config", - "//components/security_state/content", "//content/public/browser", "//services/strings", ] @@ -93,12 +90,18 @@ static_library("chrome") { if (is_linux) { sources += [ "//chrome/browser/icon_loader_auralinux.cc" ] + if (use_x11 || use_ozone) { + sources += + [ "//chrome/browser/extensions/global_shortcut_listener_linux.cc" ] + } if (use_x11) { sources += [ "//chrome/browser/extensions/global_shortcut_listener_x11.cc", "//chrome/browser/extensions/global_shortcut_listener_x11.h", ] - } else if (use_ozone) { + } + if (use_ozone) { + deps += [ "//ui/ozone" ] sources += [ "//chrome/browser/extensions/global_shortcut_listener_ozone.cc", "//chrome/browser/extensions/global_shortcut_listener_ozone.h", @@ -189,7 +192,7 @@ static_library("chrome") { } if (is_linux) { - sources += [ "//chrome/browser/media/webrtc/window_icon_util_x11.cc" ] + sources += [ "//chrome/browser/media/webrtc/window_icon_util_linux.cc" ] } } @@ -213,8 +216,6 @@ static_library("chrome") { "//chrome/browser/printing/print_job_worker.h", "//chrome/browser/printing/print_view_manager_base.cc", "//chrome/browser/printing/print_view_manager_base.h", - "//chrome/browser/printing/print_view_manager_basic.cc", - "//chrome/browser/printing/print_view_manager_basic.h", "//chrome/browser/printing/printer_query.cc", "//chrome/browser/printing/printer_query.h", "//chrome/browser/printing/printing_service.cc", @@ -251,8 +252,12 @@ static_library("chrome") { "//chrome/browser/picture_in_picture/picture_in_picture_window_manager.h", "//chrome/browser/ui/views/overlay/back_to_tab_image_button.cc", "//chrome/browser/ui/views/overlay/back_to_tab_image_button.h", + "//chrome/browser/ui/views/overlay/back_to_tab_label_button.cc", "//chrome/browser/ui/views/overlay/close_image_button.cc", "//chrome/browser/ui/views/overlay/close_image_button.h", + "//chrome/browser/ui/views/overlay/constants.h", + "//chrome/browser/ui/views/overlay/hang_up_button.cc", + "//chrome/browser/ui/views/overlay/hang_up_button.h", "//chrome/browser/ui/views/overlay/overlay_window_views.cc", "//chrome/browser/ui/views/overlay/overlay_window_views.h", "//chrome/browser/ui/views/overlay/playback_image_button.cc", @@ -261,6 +266,10 @@ static_library("chrome") { "//chrome/browser/ui/views/overlay/resize_handle_button.h", "//chrome/browser/ui/views/overlay/skip_ad_label_button.cc", "//chrome/browser/ui/views/overlay/skip_ad_label_button.h", + "//chrome/browser/ui/views/overlay/toggle_camera_button.cc", + "//chrome/browser/ui/views/overlay/toggle_camera_button.h", + "//chrome/browser/ui/views/overlay/toggle_microphone_button.cc", + "//chrome/browser/ui/views/overlay/toggle_microphone_button.h", "//chrome/browser/ui/views/overlay/track_image_button.cc", "//chrome/browser/ui/views/overlay/track_image_button.h", ] diff --git a/chromium_src/chrome/browser/certificate_manager_model.cc b/chromium_src/chrome/browser/certificate_manager_model.cc index 8a38b5370853a..4166c8b36d19c 100644 --- a/chromium_src/chrome/browser/certificate_manager_model.cc +++ b/chromium_src/chrome/browser/certificate_manager_model.cc @@ -90,7 +90,7 @@ CertificateManagerModel::~CertificateManagerModel() = default; int CertificateManagerModel::ImportFromPKCS12( PK11SlotInfo* slot_info, const std::string& data, - const base::string16& password, + const std::u16string& password, bool is_extractable, net::ScopedCERTCertificateList* imported_certs) { return cert_db_->ImportFromPKCS12(slot_info, data, password, is_extractable, diff --git a/chromium_src/chrome/browser/certificate_manager_model.h b/chromium_src/chrome/browser/certificate_manager_model.h index b68a650e24b1e..1c35071574507 100644 --- a/chromium_src/chrome/browser/certificate_manager_model.h +++ b/chromium_src/chrome/browser/certificate_manager_model.h @@ -5,14 +5,12 @@ #ifndef CHROME_BROWSER_CERTIFICATE_MANAGER_MODEL_H_ #define CHROME_BROWSER_CERTIFICATE_MANAGER_MODEL_H_ -#include #include #include #include "base/callback.h" #include "base/macros.h" #include "base/memory/ref_counted.h" -#include "base/strings/string16.h" #include "net/cert/nss_cert_database.h" namespace content { @@ -46,7 +44,7 @@ class CertificateManagerModel { // Returns a net error code on failure. int ImportFromPKCS12(PK11SlotInfo* slot_info, const std::string& data, - const base::string16& password, + const std::u16string& password, bool is_extractable, net::ScopedCERTCertificateList* imported_certs); diff --git a/chromium_src/chrome/browser/process_singleton.h b/chromium_src/chrome/browser/process_singleton.h index 5f2f38dc1276c..6367cb06f9bc6 100644 --- a/chromium_src/chrome/browser/process_singleton.h +++ b/chromium_src/chrome/browser/process_singleton.h @@ -9,9 +9,6 @@ #include #endif // defined(OS_WIN) -#include -#include - #include "base/callback.h" #include "base/command_line.h" #include "base/files/file_path.h" @@ -158,7 +155,7 @@ class ProcessSingleton { // Function to call when the other process is hung and needs to be killed. // Allows overriding for tests. - base::Callback kill_callback_; + base::RepeatingCallback kill_callback_; // Path in file system to the socket. base::FilePath socket_path_; diff --git a/default_app/default_app.ts b/default_app/default_app.ts index 7c2d8a3b9eecb..5e52422f1f304 100644 --- a/default_app/default_app.ts +++ b/default_app/default_app.ts @@ -41,19 +41,18 @@ ipcMain.handle('bootstrap', (event) => { return isTrustedSender(event.sender) ? electronPath : null; }); -async function createWindow () { +async function createWindow (backgroundColor?: string) { await app.whenReady(); const options: Electron.BrowserWindowConstructorOptions = { width: 960, height: 620, autoHideMenuBar: true, - backgroundColor: '#2f3241', + backgroundColor, webPreferences: { preload: path.resolve(__dirname, 'preload.js'), contextIsolation: true, - sandbox: true, - enableRemoteModule: false + sandbox: true }, useContentSize: true, show: false @@ -96,7 +95,7 @@ export const loadURL = async (appUrl: string) => { }; export const loadFile = async (appPath: string) => { - mainWindow = await createWindow(); + mainWindow = await createWindow(appPath === 'index.html' ? '#2f3241' : undefined); mainWindow.loadFile(appPath); mainWindow.focus(); }; diff --git a/docs/README.md b/docs/README.md index dee27988c76c0..75444671fb71b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -18,20 +18,14 @@ an issue: ## Guides and Tutorials -### Quickstart +### Getting started -* [Quick Start Guide](tutorial/quick-start.md) - * [Prerequisites](tutorial/quick-start.md#prerequisites) - * [Create a basic application](tutorial/quick-start.md#create-a-basic-application) - * [Run your application](tutorial/quick-start.md#run-your-application) - * [Package and distribute the application](tutorial/quick-start.md#package-and-distribute-the-application) +* [Introduction](tutorial/introduction.md) +* [Quick Start](tutorial/quick-start.md) +* [Process Model](tutorial/process-model.md) ### Learning the basics -* [Electron's Process Model](tutorial/quick-start.md#application-architecture) - * [Main and Renderer Processes](tutorial/quick-start.md#main-and-renderer-processes) - * [Electron API](tutorial/quick-start.md#electron-api) - * [Node.js API](tutorial/quick-start.md#nodejs-api) * Adding Features to Your App * [Notifications](tutorial/notifications.md) * [Recent Documents](tutorial/recent-documents.md) @@ -59,6 +53,7 @@ an issue: * [Using Native Node.js Modules](tutorial/using-native-node-modules.md) * [Performance Strategies](tutorial/performance.md) * [Security Strategies](tutorial/security.md) + * [Process Sandboxing](tutorial/sandbox.md) * [Accessibility](tutorial/accessibility.md) * [Manually Enabling Accessibility Features](tutorial/accessibility.md#manually-enabling-accessibility-features) * [Testing and Debugging](tutorial/application-debugging.md) @@ -68,6 +63,7 @@ an issue: * [Testing on Headless CI Systems (Travis, Jenkins)](tutorial/testing-on-headless-ci.md) * [DevTools Extension](tutorial/devtools-extension.md) * [Automated Testing with a Custom Driver](tutorial/automated-testing-with-a-custom-driver.md) + * [REPL](tutorial/repl.md) * [Distribution](tutorial/application-distribution.md) * [Supported Platforms](tutorial/support.md#supported-platforms) * [Code Signing](tutorial/code-signing.md) @@ -126,6 +122,8 @@ These individual tutorials expand on topics discussed in the guide above. * [ipcMain](api/ipc-main.md) * [Menu](api/menu.md) * [MenuItem](api/menu-item.md) +* [MessageChannelMain](api/message-channel-main.md) +* [MessagePortMain](api/message-port-main.md) * [net](api/net.md) * [netLog](api/net-log.md) * [nativeTheme](api/native-theme.md) @@ -135,6 +133,7 @@ These individual tutorials expand on topics discussed in the guide above. * [protocol](api/protocol.md) * [screen](api/screen.md) * [session](api/session.md) +* [ShareMenu](api/share-menu.md) * [systemPreferences](api/system-preferences.md) * [TouchBar](api/touch-bar.md) * [Tray](api/tray.md) @@ -144,15 +143,14 @@ These individual tutorials expand on topics discussed in the guide above. ### Modules for the Renderer Process (Web Page): * [contextBridge](api/context-bridge.md) -* [desktopCapturer](api/desktop-capturer.md) * [ipcRenderer](api/ipc-renderer.md) -* [remote](api/remote.md) * [webFrame](api/web-frame.md) ### Modules for Both Processes: * [clipboard](api/clipboard.md) * [crashReporter](api/crash-reporter.md) +* [desktopCapturer](api/desktop-capturer.md) * [nativeImage](api/native-image.md) * [shell](api/shell.md) diff --git a/docs/api/accelerator.md b/docs/api/accelerator.md index 6c5dfd1a4bfe6..f8d4cc421e689 100644 --- a/docs/api/accelerator.md +++ b/docs/api/accelerator.md @@ -35,7 +35,7 @@ Linux and Windows to define some accelerators. Use `Alt` instead of `Option`. The `Option` key only exists on macOS, whereas the `Alt` key is available on all platforms. -The `Super` key is mapped to the `Windows` key on Windows and Linux and +The `Super` (or `Meta`) key is mapped to the `Windows` key on Windows and Linux and `Cmd` on macOS. ## Available modifiers @@ -48,6 +48,7 @@ The `Super` key is mapped to the `Windows` key on Windows and Linux and * `AltGr` * `Shift` * `Super` +* `Meta` ## Available key codes diff --git a/docs/api/app.md b/docs/api/app.md index 2f01e65a91f6c..d9a967daced6f 100755 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -507,64 +507,6 @@ Returns: Emitted when `desktopCapturer.getSources()` is called in the renderer process of `webContents`. Calling `event.preventDefault()` will make it return empty sources. -### Event: 'remote-require' _Deprecated_ - -Returns: - -* `event` Event -* `webContents` [WebContents](web-contents.md) -* `moduleName` String - -Emitted when `remote.require()` is called in the renderer process of `webContents`. -Calling `event.preventDefault()` will prevent the module from being returned. -Custom value can be returned by setting `event.returnValue`. - -### Event: 'remote-get-global' _Deprecated_ - -Returns: - -* `event` Event -* `webContents` [WebContents](web-contents.md) -* `globalName` String - -Emitted when `remote.getGlobal()` is called in the renderer process of `webContents`. -Calling `event.preventDefault()` will prevent the global from being returned. -Custom value can be returned by setting `event.returnValue`. - -### Event: 'remote-get-builtin' _Deprecated_ - -Returns: - -* `event` Event -* `webContents` [WebContents](web-contents.md) -* `moduleName` String - -Emitted when `remote.getBuiltin()` is called in the renderer process of `webContents`. -Calling `event.preventDefault()` will prevent the module from being returned. -Custom value can be returned by setting `event.returnValue`. - -### Event: 'remote-get-current-window' _Deprecated_ - -Returns: - -* `event` Event -* `webContents` [WebContents](web-contents.md) - -Emitted when `remote.getCurrentWindow()` is called in the renderer process of `webContents`. -Calling `event.preventDefault()` will prevent the object from being returned. -Custom value can be returned by setting `event.returnValue`. - -### Event: 'remote-get-current-web-contents' _Deprecated_ - -Returns: - -* `event` Event -* `webContents` [WebContents](web-contents.md) - -Emitted when `remote.getCurrentWebContents()` is called in the renderer process of `webContents`. -Calling `event.preventDefault()` will prevent the object from being returned. -Custom value can be returned by setting `event.returnValue`. - ## Methods The `app` object has the following methods: @@ -753,7 +695,8 @@ Overrides the current application's name. ### `app.getLocale()` -Returns `String` - The current application locale. Possible return values are documented [here](locales.md). +Returns `String` - The current application locale, fetched using Chromium's `l10n_util` library. +Possible return values are documented [here](https://source.chromium.org/chromium/chromium/src/+/master:ui/base/l10n/l10n_util.cc). To set the locale, you'll want to use a command line switch at app startup, which may be found [here](https://github.com/electron/electron/blob/master/docs/api/command-line-switches.md). @@ -929,6 +872,10 @@ re-add a removed item to a custom category earlier than that will result in the entire custom category being omitted from the Jump List. The list of removed items can be obtained using `app.getJumpListSettings()`. +**Note:** The maximum length of a Jump List item's `description` property is +260 characters. Beyond this limit, the item will not be added to the Jump +List, nor will it be displayed. + Here's a very simple example of creating a custom Jump List: ```javascript @@ -1480,23 +1427,25 @@ This is the user agent that will be used when no user agent is set at the app has the same user agent. Set to a custom value as early as possible in your app's initialization to ensure that your overridden value is used. -### `app.allowRendererProcessReuse` +### `app.runningUnderRosettaTranslation` _macOS_ _Readonly_ _Deprecated_ -A `Boolean` which when `true` disables the overrides that Electron has in place -to ensure renderer processes are restarted on every navigation. The current -default value for this property is `true`. +A `Boolean` which when `true` indicates that the app is currently running +under the [Rosetta Translator Environment](https://en.wikipedia.org/wiki/Rosetta_(software)). -The intention is for these overrides to become disabled by default and then at -some point in the future this property will be removed. This property impacts -which native modules you can use in the renderer process. For more information -on the direction Electron is going with renderer process restarts and usage of -native modules in the renderer process please check out this -[Tracking Issue](https://github.com/electron/electron/issues/18397). +You can use this property to prompt users to download the arm64 version of +your application when they are running the x64 version under Rosetta +incorrectly. -### `app.runningUnderRosettaTranslation` _macOS_ _Readonly_ +**Deprecated:** This property is superceded by the `runningUnderARM64Translation` +property which detects when the app is being translated to ARM64 in both macOS +and Windows. -A `Boolean` which when `true` indicates that the app is currently running -under the [Rosetta Translator Environment](https://en.wikipedia.org/wiki/Rosetta_(software)). +### `app.runningUnderARM64Translation` _Readonly_ _macOS_ _Windows_ + +A `Boolean` which when `true` indicates that the app is currently running under +an ARM64 translator (like the macOS +[Rosetta Translator Environment](https://en.wikipedia.org/wiki/Rosetta_(software)) +or Windows [WOW](https://en.wikipedia.org/wiki/Windows_on_Windows)). You can use this property to prompt users to download the arm64 version of your application when they are running the x64 version under Rosetta diff --git a/docs/api/browser-view.md b/docs/api/browser-view.md index 0b7c1ef1ec8e5..dc8a5e9558082 100644 --- a/docs/api/browser-view.md +++ b/docs/api/browser-view.md @@ -1,14 +1,16 @@ -## Class: BrowserView - -> Create and control views. - -Process: [Main](../glossary.md#main-process) +# BrowserView A `BrowserView` can be used to embed additional web content into a [`BrowserWindow`](browser-window.md). It is like a child window, except that it is positioned relative to its owning window. It is meant to be an alternative to the `webview` tag. +## Class: BrowserView + +> Create and control views. + +Process: [Main](../glossary.md#main-process) + ### Example ```javascript diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 9d150fe155cea..1e5fe42d81d62 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -14,7 +14,7 @@ const win = new BrowserWindow({ width: 800, height: 600 }) win.loadURL('https://github.com') // Or load a local HTML file -win.loadURL(`file://${__dirname}/app/index.html`) +win.loadFile('index.html') ``` ## Frameless window @@ -238,7 +238,7 @@ It creates a new `BrowserWindow` with native properties as set by the `options`. window shadow and window animations. Default is `true`. * `vibrancy` String (optional) - Add a type of vibrancy effect to the window, only on macOS. Can be `appearance-based`, `light`, `dark`, `titlebar`, `selection`, - `menu`, `popover`, `sidebar`, `medium-light`, `ultra-dark`, `header`, `sheet`, `window`, `hud`, `fullscreen-ui`, `tooltip`, `content`, `under-window`, or `under-page`. Please note that using `frame: false` in combination with a vibrancy value requires that you use a non-default `titleBarStyle` as well. Also note that `appearance-based`, `light`, `dark`, `medium-light`, and `ultra-dark` are deprecated and have been removed in macOS Catalina (10.15). + `menu`, `popover`, `sidebar`, `medium-light`, `ultra-dark`, `header`, `sheet`, `window`, `hud`, `fullscreen-ui`, `tooltip`, `content`, `under-window`, or `under-page`. Please note that `appearance-based`, `light`, `dark`, `medium-light`, and `ultra-dark` are deprecated and have been removed in macOS Catalina (10.15). * `zoomToPageWidth` Boolean (optional) - Controls the behavior on macOS when option-clicking the green stoplight button on the toolbar or by clicking the Window > Zoom menu item. If `true`, the window will grow to the preferred @@ -267,14 +267,12 @@ It creates a new `BrowserWindow` with native properties as set by the `options`. be the absolute file path to the script. When node integration is turned off, the preload script can reintroduce Node global symbols back to the global scope. See example - [here](process.md#event-loaded). + [here](context-bridge.md#exposing-node-global-symbols). * `sandbox` Boolean (optional) - If set, this will sandbox the renderer associated with the window, making it compatible with the Chromium OS-level sandbox and disabling the Node.js engine. This is not the same as the `nodeIntegration` option and the APIs available to the preload script - are more limited. Read more about the option [here](sandbox-option.md). - * `enableRemoteModule` Boolean (optional) - Whether to enable the [`remote`](remote.md) module. - Default is `false`. + are more limited. Read more about the option [here](../tutorial/sandbox.md). * `session` [Session](session.md#class-session) (optional) - Sets the session used by the page. Instead of passing the Session object directly, you can also choose to use the `partition` option instead, which accepts a partition string. When @@ -286,13 +284,6 @@ It creates a new `BrowserWindow` with native properties as set by the `options`. same `partition`. If there is no `persist:` prefix, the page will use an in-memory session. By assigning the same `partition`, multiple pages can share the same session. Default is the default session. - * `affinity` String (optional) - When specified, web pages with the same - `affinity` will run in the same renderer process. Note that due to reusing - the renderer process, certain `webPreferences` options will also be shared - between the web pages even when you specified different values for them, - including but not limited to `preload`, `sandbox` and `nodeIntegration`. - So it is suggested to use exact same `webPreferences` for web pages with - the same `affinity`. _Deprecated_ * `zoomFactor` Number (optional) - The default zoom factor of the page, `3.0` represents `300%`. Default is `1.0`. * `javascript` Boolean (optional) - Enables JavaScript support. Default is `true`. @@ -350,12 +341,9 @@ It creates a new `BrowserWindow` with native properties as set by the `options`. [Chrome Content Scripts][chrome-content-scripts]. You can access this context in the dev tools by selecting the 'Electron Isolated Context' entry in the combo box at the top of the Console tab. - * `worldSafeExecuteJavaScript` Boolean (optional) - If true, values returned from `webFrame.executeJavaScript` will be sanitized to ensure JS values - can't unsafely cross between worlds when using `contextIsolation`. Defaults to `true`. _Deprecated_ * `nativeWindowOpen` Boolean (optional) - Whether to use native - `window.open()`. Defaults to `false`. Child windows will always have node - integration disabled unless `nodeIntegrationInSubFrames` is true. **Note:** This option is currently - experimental. + `window.open()`. Defaults to `true`. Child windows will always have node + integration disabled unless `nodeIntegrationInSubFrames` is true. * `webviewTag` Boolean (optional) - Whether to enable the [`` tag](webview-tag.md). Defaults to `false`. **Note:** The `preload` script configured for the `` will have node integration @@ -535,11 +523,20 @@ Returns: * `event` Event * `newBounds` [Rectangle](structures/rectangle.md) - Size the window is being resized to. +* `details` Object + * `edge` (String) - The edge of the window being dragged for resizing. Can be `bottom`, `left`, `right`, `top-left`, `top-right`, `bottom-left` or `bottom-right`. Emitted before the window is resized. Calling `event.preventDefault()` will prevent the window from being resized. Note that this is only emitted when the window is being resized manually. Resizing the window with `setBounds`/`setSize` will not emit this event. +The possible values and behaviors of the `edge` option are platform dependent. Possible values are: + +* On Windows, possible values are `bottom`, `top`, `left`, `right`, `top-left`, `top-right`, `bottom-left`, `bottom-right`. +* On macOS, possible values are `bottom` and `right`. + * The value `bottom` is used to denote vertical resizing. + * The value `right` is used to denote horizontal resizing. + #### Event: 'resize' Emitted after the window has been resized. @@ -762,6 +759,10 @@ A `Boolean` property that determines whether the window is in simple (pre-Lion) A `Boolean` property that determines whether the window is in fullscreen mode. +#### `win.focusable` _Windows_ _macOS_ + +A `Boolean` property that determines whether the window is focusable. + #### `win.visibleOnAllWorkspaces` A `Boolean` property that determines whether the window is visible on all workspaces. @@ -1300,7 +1301,7 @@ can be be used to listen to changes to tablet mode. #### `win.getMediaSourceId()` -Returns `String` - Window id in the format of DesktopCapturerSource's id. For example "window:1234:0". +Returns `String` - Window id in the format of DesktopCapturerSource's id. For example "window:1324:0". More precisely the format is `window:id:other_id` where `id` is `HWND` on Windows, `CGWindowID` (`uint64_t`) on macOS and `Window` (`unsigned long`) on @@ -1318,6 +1319,8 @@ The native type of the handle is `HWND` on Windows, `NSView*` on macOS, and * `message` Integer * `callback` Function + * `wParam` any - The `wParam` provided to the WndProc + * `lParam` any - The `lParam` provided to the WndProc Hooks a windows message. The `callback` is called when the message is received in the WndProc. @@ -1370,7 +1373,7 @@ Returns `Boolean` - Whether the window's document has been edited. Returns `Promise` - Resolves with a [NativeImage](native-image.md) -Captures a snapshot of the page within `rect`. Omitting `rect` will capture the whole visible page. +Captures a snapshot of the page within `rect`. Omitting `rect` will capture the whole visible page. If the page is not visible, `rect` may be empty. #### `win.loadURL(url[, options])` @@ -1379,7 +1382,7 @@ Captures a snapshot of the page within `rect`. Omitting `rect` will capture the * `httpReferrer` (String | [Referrer](structures/referrer.md)) (optional) - An HTTP Referrer URL. * `userAgent` String (optional) - A user agent originating the request. * `extraHeaders` String (optional) - Extra headers separated by "\n" - * `postData` ([UploadRawData[]](structures/upload-raw-data.md) | [UploadFile[]](structures/upload-file.md)) (optional) + * `postData` ([UploadRawData](structures/upload-raw-data.md) | [UploadFile](structures/upload-file.md))[] (optional) * `baseURLForDataURL` String (optional) - Base URL (with trailing path separator) for files to be loaded by the data URL. This is needed only if the specified `url` is a data URL and needs to load other files. Returns `Promise` - the promise will resolve when the page has finished loading @@ -1678,6 +1681,10 @@ Changes whether the window can be focused. On macOS it does not remove the focus from the window. +#### `win.isFocusable()` _macOS_ _Windows_ + +Returns whether the window can be focused. + #### `win.setParentWindow(parent)` * `parent` BrowserWindow | null diff --git a/docs/api/command-line-switches.md b/docs/api/command-line-switches.md index 902e2c836c844..b125f128c635b 100644 --- a/docs/api/command-line-switches.md +++ b/docs/api/command-line-switches.md @@ -66,11 +66,6 @@ Forces the maximum disk space to be used by the disk cache, in bytes. Enables caller stack logging for the following APIs (filtering events): * `desktopCapturer.getSources()` / `desktop-capturer-get-sources` -* `remote.require()` / `remote-require` -* `remote.getGlobal()` / `remote-get-builtin` -* `remote.getBuiltin()` / `remote-get-global` -* `remote.getCurrentWindow()` / `remote-get-current-window` -* `remote.getCurrentWebContents()` / `remote-get-current-web-contents` ### --enable-logging @@ -80,6 +75,12 @@ This switch can not be used in `app.commandLine.appendSwitch` since it is parsed earlier than user's app is loaded, but you can set the `ELECTRON_ENABLE_LOGGING` environment variable to achieve the same effect. +### --force-fieldtrials=`trials` + +Field trials to be forcefully enabled or disabled. + +For example: `WebRTC-Audio-Red-For-Opus/Enabled/` + ### --host-rules=`rules` A comma-separated list of `rules` that control how hostnames are mapped. @@ -136,7 +137,8 @@ proxy server flags that are passed. ### --no-sandbox -Disables Chromium sandbox, which is now enabled by default. +Disables the Chromium [sandbox](https://www.chromium.org/developers/design-documents/sandbox). +Forces renderer process and Chromium helper processes to run un-sandboxed. Should only be used for testing. ### --proxy-bypass-list=`hosts` diff --git a/docs/api/context-bridge.md b/docs/api/context-bridge.md index ab157f79f64f4..8db3006cc9ba9 100644 --- a/docs/api/context-bridge.md +++ b/docs/api/context-bridge.md @@ -33,7 +33,7 @@ page you load in your renderer executes code in this world. ### Isolated World -When `contextIsolation` is enabled in your `webPreferences`, your `preload` scripts run in an +When `contextIsolation` is enabled in your `webPreferences` (this is the default behavior since Electron 12.0.0), your `preload` scripts run in an "Isolated World". You can read more about context isolation and what it affects in the [security](../tutorial/security.md#3-enable-context-isolation-for-remote-content) docs. @@ -107,6 +107,26 @@ has been included below for completeness: | `Function` | Complex | ✅ | ✅ | Prototype modifications are dropped. Sending classes or constructors will not work. | | [Cloneable Types](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm) | Simple | ✅ | ✅ | See the linked document on cloneable types | | `Element` | Complex | ✅ | ✅ | Prototype modifications are dropped. Sending custom elements will not work. | +| `Blob` | Complex | ✅ | ✅ | N/A | | `Symbol` | N/A | ❌ | ❌ | Symbols cannot be copied across contexts so they are dropped | If the type you care about is not in the above table, it is probably not supported. + +### Exposing Node Global Symbols + +The `contextBridge` can be used by the preload script to give your renderer access to Node APIs. +The table of supported types described above also applies to Node APIs that you expose through `contextBridge`. +Please note that many Node APIs grant access to local system resources. +Be very cautious about which globals and APIs you expose to untrusted remote content. + +```javascript +const { contextBridge } = require('electron') +const crypto = require('crypto') +contextBridge.exposeInMainWorld('nodeCrypto', { + sha256sum (data) { + const hash = crypto.createHash('sha256') + hash.update(data) + return hash.digest('hex') + } +}) +``` diff --git a/docs/api/cookies.md b/docs/api/cookies.md index 4eab77d4d5996..cd598bfeece88 100644 --- a/docs/api/cookies.md +++ b/docs/api/cookies.md @@ -45,6 +45,8 @@ The following events are available on instances of `Cookies`: #### Event: 'changed' +Returns: + * `event` Event * `cookie` [Cookie](structures/cookie.md) - The cookie that was changed. * `cause` String - The cause of the change with one of the following values: diff --git a/docs/api/crash-reporter.md b/docs/api/crash-reporter.md index c03f8a7e0398e..8331bc8d43f52 100644 --- a/docs/api/crash-reporter.md +++ b/docs/api/crash-reporter.md @@ -77,7 +77,8 @@ The `crashReporter` module has the following methods: ### `crashReporter.start(options)` * `options` Object - * `submitURL` String - URL that crash reports will be sent to as POST. + * `submitURL` String (optional) - URL that crash reports will be sent to as + POST. Required unless `uploadToServer` is `false`. * `productName` String (optional) - Defaults to `app.name`. * `companyName` String (optional) _Deprecated_ - Deprecated alias for `{ globalExtra: { _companyName: ... } }`. diff --git a/docs/api/dialog.md b/docs/api/dialog.md index 483ff271d2372..43c7a6e884943 100644 --- a/docs/api/dialog.md +++ b/docs/api/dialog.md @@ -154,7 +154,7 @@ dialog.showOpenDialog(mainWindow, { * `browserWindow` [BrowserWindow](browser-window.md) (optional) * `options` Object - * `title` String (optional) + * `title` String (optional) - The dialog title. Cannot be displayed on some _Linux_ desktop environments. * `defaultPath` String (optional) - Absolute directory path, absolute file path, or file name to use by default. * `buttonLabel` String (optional) - Custom label for the confirmation button, when @@ -185,7 +185,7 @@ The `filters` specifies an array of file types that can be displayed, see * `browserWindow` [BrowserWindow](browser-window.md) (optional) * `options` Object - * `title` String (optional) + * `title` String (optional) - The dialog title. Cannot be displayed on some _Linux_ desktop environments. * `defaultPath` String (optional) - Absolute directory path, absolute file path, or file name to use by default. * `buttonLabel` String (optional) - Custom label for the confirmation button, when @@ -233,10 +233,6 @@ expanding and collapsing the dialog. be selected by default when the message box opens. * `title` String (optional) - Title of the message box, some platforms will not show it. * `detail` String (optional) - Extra information of the message. - * `checkboxLabel` String (optional) - If provided, the message box will - include a checkbox with the given label. - * `checkboxChecked` Boolean (optional) - Initial checked state of the - checkbox. `false` by default. * `icon` ([NativeImage](native-image.md) | String) (optional) * `cancelId` Integer (optional) - The index of the button to be used to cancel the dialog, via the `Esc` key. By default this is assigned to the first button with "cancel" or "no" as the diff --git a/docs/api/frameless-window.md b/docs/api/frameless-window.md index 84290119edce2..8bb253e1948c2 100644 --- a/docs/api/frameless-window.md +++ b/docs/api/frameless-window.md @@ -83,8 +83,10 @@ win.show() blur effect to the content below the window (i.e. other applications open on the user's system). * The window will not be transparent when DevTools is opened. -* On Windows operating systems, transparent windows will not work when DWM is +* On Windows operating systems, + * transparent windows will not work when DWM is disabled. + * transparent windows can not be maximized using the Windows system menu or by double clicking the title bar. The reasoning behind this can be seen on [this pull request](https://github.com/electron/electron/pull/28207). * On Linux, users have to put `--enable-transparent-visuals --disable-gpu` in the command line to disable GPU and allow ARGB to make transparent window, this is caused by an upstream bug that [alpha channel doesn't work on some diff --git a/docs/api/locales.md b/docs/api/locales.md deleted file mode 100644 index a45fdbcbe5774..0000000000000 --- a/docs/api/locales.md +++ /dev/null @@ -1,142 +0,0 @@ -# Locales - -> Locale values returned by `app.getLocale()`. - -Electron uses Chromium's `l10n_util` library to fetch the locale. Possible -values are listed below: - -| Language Code | Language Name | -|---------------|---------------| -| af | Afrikaans | -| am | Amharic | -| ar | Arabic | -| az | Azerbaijani | -| be | Belarusian | -| bg | Bulgarian | -| bh | Bihari | -| bn | Bengali | -| br | Breton | -| bs | Bosnian | -| ca | Catalan | -| co | Corsican | -| cs | Czech | -| cy | Welsh | -| da | Danish | -| de | German | -| de-AT | German (Austria) | -| de-CH | German (Switzerland) | -| de-DE | German (Germany) | -| el | Greek | -| en | English | -| en-AU | English (Australia) | -| en-CA | English (Canada) | -| en-GB | English (UK) | -| en-NZ | English (New Zealand) | -| en-US | English (US) | -| en-ZA | English (South Africa) | -| eo | Esperanto | -| es | Spanish | -| es-419 | Spanish (Latin America) | -| et | Estonian | -| eu | Basque | -| fa | Persian | -| fi | Finnish | -| fil | Filipino | -| fo | Faroese | -| fr | French | -| fr-CA | French (Canada) | -| fr-CH | French (Switzerland) | -| fr-FR | French (France) | -| fy | Frisian | -| ga | Irish | -| gd | Scots Gaelic | -| gl | Galician | -| gn | Guarani | -| gu | Gujarati | -| ha | Hausa | -| haw | Hawaiian | -| he | Hebrew | -| hi | Hindi | -| hr | Croatian | -| hu | Hungarian | -| hy | Armenian | -| ia | Interlingua | -| id | Indonesian | -| is | Icelandic | -| it | Italian | -| it-CH | Italian (Switzerland) | -| it-IT | Italian (Italy) | -| ja | Japanese | -| jw | Javanese | -| ka | Georgian | -| kk | Kazakh | -| km | Cambodian | -| kn | Kannada | -| ko | Korean | -| ku | Kurdish | -| ky | Kyrgyz | -| la | Latin | -| ln | Lingala | -| lo | Laothian | -| lt | Lithuanian | -| lv | Latvian | -| mk | Macedonian | -| ml | Malayalam | -| mn | Mongolian | -| mo | Moldavian | -| mr | Marathi | -| ms | Malay | -| mt | Maltese | -| nb | Norwegian (Bokmal) | -| ne | Nepali | -| nl | Dutch | -| nn | Norwegian (Nynorsk) | -| no | Norwegian | -| oc | Occitan | -| om | Oromo | -| or | Oriya | -| pa | Punjabi | -| pl | Polish | -| ps | Pashto | -| pt | Portuguese | -| pt-BR | Portuguese (Brazil) | -| pt-PT | Portuguese (Portugal) | -| qu | Quechua | -| rm | Romansh | -| ro | Romanian | -| ru | Russian | -| sd | Sindhi | -| sh | Serbo-Croatian | -| si | Sinhalese | -| sk | Slovak | -| sl | Slovenian | -| sn | Shona | -| so | Somali | -| sq | Albanian | -| sr | Serbian | -| st | Sesotho | -| su | Sundanese | -| sv | Swedish | -| sw | Swahili | -| ta | Tamil | -| te | Telugu | -| tg | Tajik | -| th | Thai | -| ti | Tigrinya | -| tk | Turkmen | -| to | Tonga | -| tr | Turkish | -| tt | Tatar | -| tw | Twi | -| ug | Uighur | -| uk | Ukrainian | -| ur | Urdu | -| uz | Uzbek | -| vi | Vietnamese | -| xh | Xhosa | -| yi | Yiddish | -| yo | Yoruba | -| zh | Chinese | -| zh-CN | Chinese (Simplified) | -| zh-TW | Chinese (Traditional) | -| zu | Zulu | diff --git a/docs/api/menu.md b/docs/api/menu.md index ba93a9245ed94..cdd1dc2f4edb0 100644 --- a/docs/api/menu.md +++ b/docs/api/menu.md @@ -1,3 +1,5 @@ +# Menu + ## Class: Menu > Create native application menus and context menus. diff --git a/docs/api/message-channel-main.md b/docs/api/message-channel-main.md index 86cdce4e5099b..670cda868f599 100644 --- a/docs/api/message-channel-main.md +++ b/docs/api/message-channel-main.md @@ -9,12 +9,15 @@ channel messaging. ## Class: MessageChannelMain +> Channel interface for channel messaging in the main process. + Process: [Main](../glossary.md#main-process) Example: ```js // Main process +const { MessageChannelMain } = require('electron') const { port1, port2 } = new MessageChannelMain() w.webContents.postMessage('port', null, [port2]) port1.postMessage({ some: 'message' }) diff --git a/docs/api/message-port-main.md b/docs/api/message-port-main.md index 2f75f2f996fc2..6c84c28c49bbc 100644 --- a/docs/api/message-port-main.md +++ b/docs/api/message-port-main.md @@ -14,6 +14,8 @@ channel messaging. ## Class: MessagePortMain +> Port interface for channel messaging in the main process. + Process: [Main](../glossary.md#main-process) ### Instance Methods diff --git a/docs/api/process.md b/docs/api/process.md index ee00672129ff6..3f0d2ed867cd8 100644 --- a/docs/api/process.md +++ b/docs/api/process.md @@ -30,11 +30,13 @@ In sandboxed renderers the `process` object contains only a subset of the APIs: * `arch` * `platform` * `sandboxed` +* `contextIsolated` * `type` * `version` * `versions` * `mas` * `windowsStore` +* `contextId` ## Events @@ -43,19 +45,6 @@ In sandboxed renderers the `process` object contains only a subset of the APIs: Emitted when Electron has loaded its internal initialization script and is beginning to load the web page or the main script. -It can be used by the preload script to add removed Node global symbols back to -the global scope when node integration is turned off: - -```javascript -// preload.js -const _setImmediate = setImmediate -const _clearImmediate = clearImmediate -process.once('loaded', () => { - global.setImmediate = _setImmediate - global.clearImmediate = _clearImmediate -}) -``` - ## Properties ### `process.defaultApp` _Readonly_ @@ -93,6 +82,11 @@ A `String` representing the path to the resources directory. A `Boolean`. When the renderer process is sandboxed, this property is `true`, otherwise it is `undefined`. +### `process.contextIsolated` _Readonly_ + +A `Boolean` that indicates whether the current renderer context has `contextIsolation` enabled. +It is `undefined` in the main process. + ### `process.throwDeprecation` A `Boolean` that controls whether or not deprecation warnings will be thrown as @@ -133,6 +127,13 @@ A `String` representing Electron's version string. A `Boolean`. If the app is running as a Windows Store app (appx), this property is `true`, for otherwise it is `undefined`. +### `process.contextId` _Readonly_ + +A `String` (optional) representing a globally unique ID of the current JavaScript context. +Each frame has its own JavaScript context. When contextIsolation is enabled, the isolated +world also has a separate JavaScript context. +This property is only available in the renderer process. + ## Methods The `process` object has the following methods: diff --git a/docs/api/remote.md b/docs/api/remote.md deleted file mode 100644 index 063330550d3a0..0000000000000 --- a/docs/api/remote.md +++ /dev/null @@ -1,217 +0,0 @@ -# remote - -> Use main process modules from the renderer process. - -Process: [Renderer](../glossary.md#renderer-process) - -> ⚠️ WARNING ⚠️ -> The `remote` module is [deprecated](https://github.com/electron/electron/issues/21408). -> Instead of `remote`, use [`ipcRenderer`](ipc-renderer.md) and -> [`ipcMain`](ipc-main.md). -> -> Read more about why the `remote` module is deprecated [here](https://medium.com/@nornagon/electrons-remote-module-considered-harmful-70d69500f31). -> -> If you still want to use `remote` despite the performance and security -> concerns, see [@electron/remote](https://github.com/electron/remote). - -The `remote` module provides a simple way to do inter-process communication -(IPC) between the renderer process (web page) and the main process. - -In Electron, GUI-related modules (such as `dialog`, `menu` etc.) are only -available in the main process, not in the renderer process. In order to use them -from the renderer process, the `ipc` module is necessary to send inter-process -messages to the main process. With the `remote` module, you can invoke methods -of the main process object without explicitly sending inter-process messages, -similar to Java's [RMI][rmi]. An example of creating a browser window from a -renderer process: - -```javascript -const { BrowserWindow } = require('electron').remote -const win = new BrowserWindow({ width: 800, height: 600 }) -win.loadURL('https://github.com') -``` - -**Note:** For the reverse (access the renderer process from the main process), -you can use [webContents.executeJavaScript](web-contents.md#contentsexecutejavascriptcode-usergesture). - -**Note:** The remote module can be disabled for security reasons in the following contexts: - -* [`BrowserWindow`](browser-window.md) - by setting the `enableRemoteModule` option to `false`. -* [``](webview-tag.md) - by setting the `enableremotemodule` attribute to `false`. - -## Remote Objects - -Each object (including functions) returned by the `remote` module represents an -object in the main process (we call it a remote object or remote function). -When you invoke methods of a remote object, call a remote function, or create -a new object with the remote constructor (function), you are actually sending -synchronous inter-process messages. - -In the example above, both [`BrowserWindow`](browser-window.md) and `win` were remote objects and -`new BrowserWindow` didn't create a `BrowserWindow` object in the renderer -process. Instead, it created a `BrowserWindow` object in the main process and -returned the corresponding remote object in the renderer process, namely the -`win` object. - -**Note:** Only [enumerable properties][enumerable-properties] which are present -when the remote object is first referenced are accessible via remote. - -**Note:** Arrays and Buffers are copied over IPC when accessed via the `remote` -module. Modifying them in the renderer process does not modify them in the main -process and vice versa. - -## Lifetime of Remote Objects - -Electron makes sure that as long as the remote object in the renderer process -lives (in other words, has not been garbage collected), the corresponding object -in the main process will not be released. When the remote object has been -garbage collected, the corresponding object in the main process will be -dereferenced. - -If the remote object is leaked in the renderer process (e.g. stored in a map but -never freed), the corresponding object in the main process will also be leaked, -so you should be very careful not to leak remote objects. - -Primary value types like strings and numbers, however, are sent by copy. - -## Passing callbacks to the main process - -Code in the main process can accept callbacks from the renderer - for instance -the `remote` module - but you should be extremely careful when using this -feature. - -First, in order to avoid deadlocks, the callbacks passed to the main process -are called asynchronously. You should not expect the main process to -get the return value of the passed callbacks. - -For instance you can't use a function from the renderer process in an -`Array.map` called in the main process: - -```javascript -// main process mapNumbers.js -exports.withRendererCallback = (mapper) => { - return [1, 2, 3].map(mapper) -} - -exports.withLocalCallback = () => { - return [1, 2, 3].map(x => x + 1) -} -``` - -```javascript -// renderer process -const mapNumbers = require('electron').remote.require('./mapNumbers') -const withRendererCb = mapNumbers.withRendererCallback(x => x + 1) -const withLocalCb = mapNumbers.withLocalCallback() - -console.log(withRendererCb, withLocalCb) -// [undefined, undefined, undefined], [2, 3, 4] -``` - -As you can see, the renderer callback's synchronous return value was not as -expected, and didn't match the return value of an identical callback that lives -in the main process. - -Second, the callbacks passed to the main process will persist until the -main process garbage-collects them. - -For example, the following code seems innocent at first glance. It installs a -callback for the `close` event on a remote object: - -```javascript -require('electron').remote.getCurrentWindow().on('close', () => { - // window was closed... -}) -``` - -But remember the callback is referenced by the main process until you -explicitly uninstall it. If you do not, each time you reload your window the -callback will be installed again, leaking one callback for each restart. - -To make things worse, since the context of previously installed callbacks has -been released, exceptions will be raised in the main process when the `close` -event is emitted. - -To avoid this problem, ensure you clean up any references to renderer callbacks -passed to the main process. This involves cleaning up event handlers, or -ensuring the main process is explicitly told to dereference callbacks that came -from a renderer process that is exiting. - -## Accessing built-in modules in the main process - -The built-in modules in the main process are added as getters in the `remote` -module, so you can use them directly like the `electron` module. - -```javascript -const app = require('electron').remote.app -console.log(app) -``` - -## Methods - -The `remote` module has the following methods: - -### `remote.getCurrentWindow()` - -Returns [`BrowserWindow`](browser-window.md) - The window to which this web page -belongs. - -**Note:** Do not use `removeAllListeners` on [`BrowserWindow`](browser-window.md). -Use of this can remove all [`blur`](https://developer.mozilla.org/en-US/docs/Web/Events/blur) -listeners, disable click events on touch bar buttons, and other unintended -consequences. - -### `remote.getCurrentWebContents()` - -Returns [`WebContents`](web-contents.md) - The web contents of this web page. - -### `remote.getGlobal(name)` - -* `name` String - -Returns `any` - The global variable of `name` (e.g. `global[name]`) in the main -process. - -## Properties - -### `remote.require` - -A `NodeJS.Require` function equivalent to `require(module)` in the main process. -Modules specified by their relative path will resolve relative to the entrypoint -of the main process. - -e.g. - -```sh -project/ -├── main -│   ├── foo.js -│   └── index.js -├── package.json -└── renderer - └── index.js -``` - -```js -// main process: main/index.js -const { app } = require('electron') -app.whenReady().then(() => { /* ... */ }) -``` - -```js -// some relative module: main/foo.js -module.exports = 'bar' -``` - -```js -// renderer process: renderer/index.js -const foo = require('electron').remote.require('./foo') // bar -``` - -### `remote.process` _Readonly_ - -A `NodeJS.Process` object. The `process` object in the main process. This is the same as -`remote.getGlobal('process')` but is cached. - -[rmi]: https://en.wikipedia.org/wiki/Java_remote_method_invocation -[enumerable-properties]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties diff --git a/docs/api/sandbox-option.md b/docs/api/sandbox-option.md deleted file mode 100644 index da8b530911fdd..0000000000000 --- a/docs/api/sandbox-option.md +++ /dev/null @@ -1,182 +0,0 @@ -# `sandbox` Option - -> Create a browser window with a sandboxed renderer. With this -option enabled, the renderer must communicate via IPC to the main process in order to access node APIs. - -One of the key security features of Chromium is that all blink rendering/JavaScript -code is executed within a sandbox. This sandbox uses OS-specific features to ensure -that exploits in the renderer process cannot harm the system. - -In other words, when the sandbox is enabled, the renderers can only make changes -to the system by delegating tasks to the main process via IPC. -[Here's](https://www.chromium.org/developers/design-documents/sandbox) more -information about the sandbox. - -Since a major feature in Electron is the ability to run Node.js in the -renderer process (making it easier to develop desktop applications using web -technologies), the sandbox is disabled by electron. This is because -most Node.js APIs require system access. `require()` for example, is not -possible without file system permissions, which are not available in a sandboxed -environment. - -Usually this is not a problem for desktop applications since the code is always -trusted, but it makes Electron less secure than Chromium for displaying -untrusted web content. For applications that require more security, the -`sandbox` flag will force Electron to spawn a classic Chromium renderer that is -compatible with the sandbox. - -A sandboxed renderer doesn't have a Node.js environment running and doesn't -expose Node.js JavaScript APIs to client code. The only exception is the preload script, -which has access to a subset of the Electron renderer API. - -Another difference is that sandboxed renderers don't modify any of the default -JavaScript APIs. Consequently, some APIs such as `window.open` will work as they -do in Chromium (i.e. they do not return a [`BrowserWindowProxy`](browser-window-proxy.md)). - -## Example - -To create a sandboxed window, pass `sandbox: true` to `webPreferences`: - -```js -let win -app.whenReady().then(() => { - win = new BrowserWindow({ - webPreferences: { - sandbox: true - } - }) - win.loadURL('http://google.com') -}) -``` - -In the above code the [`BrowserWindow`](browser-window.md) that was created has Node.js disabled and can communicate -only via IPC. The use of this option stops Electron from creating a Node.js runtime in the renderer. Also, -within this new window `window.open` follows the native behavior (by default Electron creates a [`BrowserWindow`](browser-window.md) -and returns a proxy to this via `window.open`). - -[`app.enableSandbox`](app.md#appenablesandbox) can be used to force `sandbox: true` for all `BrowserWindow` instances. - -```js -let win -app.enableSandbox() -app.whenReady().then(() => { - // no need to pass `sandbox: true` since `app.enableSandbox()` was called. - win = new BrowserWindow() - win.loadURL('http://google.com') -}) -``` - -## Preload - -An app can make customizations to sandboxed renderers using a preload script. -Here's an example: - -```js -let win -app.whenReady().then(() => { - win = new BrowserWindow({ - webPreferences: { - sandbox: true, - preload: path.join(app.getAppPath(), 'preload.js') - } - }) - win.loadURL('http://google.com') -}) -``` - -and preload.js: - -```js -// This file is loaded whenever a javascript context is created. It runs in a -// private scope that can access a subset of Electron renderer APIs. Without -// contextIsolation enabled, it's possible to accidentally leak privileged -// globals like ipcRenderer to web content. -const { ipcRenderer } = require('electron') - -const defaultWindowOpen = window.open - -window.open = function customWindowOpen (url, ...args) { - ipcRenderer.send('report-window-open', location.origin, url, args) - return defaultWindowOpen(url + '?from_electron=1', ...args) -} -``` - -Important things to notice in the preload script: - -- Even though the sandboxed renderer doesn't have Node.js running, it still has - access to a limited node-like environment: `Buffer`, `process`, `setImmediate`, - `clearImmediate` and `require` are available. -- The preload script must be contained in a single script, but it is possible to have - complex preload code composed with multiple modules by using a tool like - webpack or browserify. An example of using browserify is below. - -To create a browserify bundle and use it as a preload script, something like -the following should be used: - -```sh - browserify preload/index.js \ - -x electron \ - --insert-global-vars=__filename,__dirname -o preload.js -``` - -The `-x` flag should be used with any required module that is already exposed in -the preload scope, and tells browserify to use the enclosing `require` function -for it. `--insert-global-vars` will ensure that `process`, `Buffer` and -`setImmediate` are also taken from the enclosing scope(normally browserify -injects code for those). - -Currently the `require` function provided in the preload scope exposes the -following modules: - -- `electron` - - `crashReporter` - - `desktopCapturer` - - `ipcRenderer` - - `nativeImage` - - `webFrame` -- `events` -- `timers` -- `url` - -More may be added as needed to expose more Electron APIs in the sandbox. - -## Rendering untrusted content - -Rendering untrusted content in Electron is still somewhat uncharted territory, -though some apps are finding success (e.g. Beaker Browser). Our goal is to get -as close to Chrome as we can in terms of the security of sandboxed content, but -ultimately we will always be behind due to a few fundamental issues: - -1. We do not have the dedicated resources or expertise that Chromium has to - apply to the security of its product. We do our best to make use of what we - have, to inherit everything we can from Chromium, and to respond quickly to - security issues, but Electron cannot be as secure as Chromium without the - resources that Chromium is able to dedicate. -2. Some security features in Chrome (such as Safe Browsing and Certificate - Transparency) require a centralized authority and dedicated servers, both of - which run counter to the goals of the Electron project. As such, we disable - those features in Electron, at the cost of the associated security they - would otherwise bring. -3. There is only one Chromium, whereas there are many thousands of apps built - on Electron, all of which behave slightly differently. Accounting for those - differences can yield a huge possibility space, and make it challenging to - ensure the security of the platform in unusual use cases. -4. We can't push security updates to users directly, so we rely on app vendors - to upgrade the version of Electron underlying their app in order for - security updates to reach users. - -Here are some things to consider before rendering untrusted content: - -- A preload script can accidentally leak privileged APIs to untrusted code, - unless [`contextIsolation`](../tutorial/security.md#3-enable-context-isolation-for-remote-content) - is also enabled. -- Some bug in the V8 engine may allow malicious code to access the renderer - preload APIs, effectively granting full access to the system through the - `remote` module. Therefore, it is highly recommended to [disable the `remote` - module](../tutorial/security.md#15-disable-the-remote-module). - If disabling is not feasible, you should selectively [filter the `remote` - module](../tutorial/security.md#16-filter-the-remote-module). -- While we make our best effort to backport Chromium security fixes to older - versions of Electron, we do not make a guarantee that every fix will be - backported. Your best chance at staying secure is to be on the latest stable - version of Electron. diff --git a/docs/api/session.md b/docs/api/session.md index 25b3af870453c..7e933743c9d90 100644 --- a/docs/api/session.md +++ b/docs/api/session.md @@ -197,9 +197,7 @@ be managed by using [ses.setPermissionCheckHandler(handler)](#sessetpermissionch with the `serial` permission. Because this is an experimental feature it is disabled by default. To enable this feature, you -will need to use the `--enable-features=ElectronSerialChooser` command line switch. Additionally -because this is an experimental Chromium feature you will need to set `enableBlinkFeatures: 'Serial'` -on the `webPreferences` property when opening a BrowserWindow. +will need to use the `--enable-features=ElectronSerialChooser` command line switch. ```javascript const { app, BrowserWindow } = require('electron') @@ -210,10 +208,7 @@ app.commandLine.appendSwitch('enable-features', 'ElectronSerialChooser') app.whenReady().then(() => { win = new BrowserWindow({ width: 800, - height: 600, - webPreferences: { - enableBlinkFeatures: 'Serial' - } + height: 600 }) win.webContents.session.on('select-serial-port', (event, portList, webContents, callback) => { event.preventDefault() @@ -822,6 +817,11 @@ Returns `Extension[]` - A list of all loaded extensions. **Note:** This API cannot be called before the `ready` event of the `app` module is emitted. +#### `ses.getStoragePath()` + +A `String | null` indicating the absolute file system path where data for this +session is persisted on disk. For in memory sessions this returns `null`. + ### Instance Properties The following properties are available on instances of `Session`: @@ -835,6 +835,11 @@ code to the `setSpellCheckerLanguages` API that isn't in this array will result A `Boolean` indicating whether builtin spell checker is enabled. +#### `ses.storagePath` _Readonly_ + +A `String | null` indicating the absolute file system path where data for this +session is persisted on disk. For in memory sessions this returns `null`. + #### `ses.cookies` _Readonly_ A [`Cookies`](cookies.md) object for this session. diff --git a/docs/api/share-menu.md b/docs/api/share-menu.md index 007028db3bc95..61e64ab912b47 100644 --- a/docs/api/share-menu.md +++ b/docs/api/share-menu.md @@ -1,8 +1,4 @@ -## Class: ShareMenu - -> Create share menu on macOS. - -Process: [Main](../glossary.md#main-process) +# ShareMenu The `ShareMenu` class creates [Share Menu][share-menu] on macOS, which can be used to share information from the current context to apps, social media @@ -11,6 +7,12 @@ accounts, and other services. For including the share menu as a submenu of other menus, please use the `shareMenu` role of [`MenuItem`](menu-item.md). +## Class: ShareMenu + +> Create share menu on macOS. + +Process: [Main](../glossary.md#main-process) + ### `new ShareMenu(sharingItem)` * `sharingItem` SharingItem - The item to share. diff --git a/docs/api/structures/jump-list-category.md b/docs/api/structures/jump-list-category.md index 07627e78c98e7..0f27f2085f6eb 100644 --- a/docs/api/structures/jump-list-category.md +++ b/docs/api/structures/jump-list-category.md @@ -19,3 +19,7 @@ property set then its `type` is assumed to be `tasks`. If the `name` property is set but the `type` property is omitted then the `type` is assumed to be `custom`. + +**Note:** The maximum length of a Jump List item's `description` property is +260 characters. Beyond this limit, the item will not be added to the Jump +List, nor will it be displayed. diff --git a/docs/api/structures/jump-list-item.md b/docs/api/structures/jump-list-item.md index d75637cb472dc..491abf80d301d 100644 --- a/docs/api/structures/jump-list-item.md +++ b/docs/api/structures/jump-list-item.md @@ -17,7 +17,7 @@ * `title` String (optional) - The text to be displayed for the item in the Jump List. Should only be set if `type` is `task`. * `description` String (optional) - Description of the task (displayed in a tooltip). - Should only be set if `type` is `task`. + Should only be set if `type` is `task`. Maximum length 260 characters. * `iconPath` String (optional) - The absolute path to an icon to be displayed in a Jump List, which can be an arbitrary resource file that contains an icon (e.g. `.ico`, `.exe`, `.dll`). You can usually specify `process.execPath` to diff --git a/docs/api/structures/post-body.md b/docs/api/structures/post-body.md index baa479dda3f05..686a55969c08b 100644 --- a/docs/api/structures/post-body.md +++ b/docs/api/structures/post-body.md @@ -1,6 +1,6 @@ # PostBody Object -* `data` Array<[PostData](./post-data.md)> - The post data to be sent to the +* `data` ([UploadRawData](upload-raw-data.md) | [UploadFile](upload-file.md))[] - The post data to be sent to the new window. * `contentType` String - The `content-type` header used for the data. One of `application/x-www-form-urlencoded` or `multipart/form-data`. Corresponds to diff --git a/docs/api/structures/post-data.md b/docs/api/structures/post-data.md deleted file mode 100644 index b63f20a95051b..0000000000000 --- a/docs/api/structures/post-data.md +++ /dev/null @@ -1,21 +0,0 @@ -# PostData Object - -* `type` String - One of the following: - * `rawData` - The data is available as a `Buffer`, in the `rawData` field. - * `file` - The object represents a file. The `filePath`, `offset`, `length` - and `modificationTime` fields will be used to describe the file. - * `blob` - The object represents a `Blob`. The `blobUUID` field will be used - to describe the `Blob`. -* `bytes` String (optional) - The raw bytes of the post data in a `Buffer`. - Required for the `rawData` type. -* `filePath` String (optional) - The path of the file being uploaded. Required - for the `file` type. -* `blobUUID` String (optional) - The `UUID` of the `Blob` being uploaded. - Required for the `blob` type. -* `offset` Integer (optional) - The offset from the beginning of the file being - uploaded, in bytes. Only valid for `file` types. -* `length` Integer (optional) - The length of the file being uploaded, in bytes. - If set to `-1`, the whole file will be uploaded. Only valid for `file` types. -* `modificationTime` Double (optional) - The modification time of the file - represented by a double, which is the number of seconds since the `UNIX Epoch` - (Jan 1, 1970). Only valid for `file` types. diff --git a/docs/api/structures/upload-file.md b/docs/api/structures/upload-file.md index ae231bdaf895f..b7cdd98aab8a9 100644 --- a/docs/api/structures/upload-file.md +++ b/docs/api/structures/upload-file.md @@ -1,6 +1,6 @@ # UploadFile Object -* `type` String - `file`. +* `type` 'file' - `file`. * `filePath` String - Path of file to be uploaded. * `offset` Integer - Defaults to `0`. * `length` Integer - Number of bytes to read from `offset`. diff --git a/docs/api/structures/upload-raw-data.md b/docs/api/structures/upload-raw-data.md index 4fe162311fa1f..e80eaa9075833 100644 --- a/docs/api/structures/upload-raw-data.md +++ b/docs/api/structures/upload-raw-data.md @@ -1,4 +1,4 @@ # UploadRawData Object -* `type` String - `rawData`. +* `type` 'rawData' - `rawData`. * `bytes` Buffer - Data to be uploaded. diff --git a/docs/api/structures/user-default-types.md b/docs/api/structures/user-default-types.md new file mode 100644 index 0000000000000..e3ce82b666dfe --- /dev/null +++ b/docs/api/structures/user-default-types.md @@ -0,0 +1,12 @@ +# UserDefaultTypes Object + +* `string` String +* `boolean` Boolean +* `integer` Number +* `float` Number +* `double` Number +* `url` String +* `array` Array\ +* `dictionary` Record\ + +This type is a helper alias, no object will never exist of this type. diff --git a/docs/api/synopsis.md b/docs/api/synopsis.md index ce1349615e32b..667c1dcd35a4d 100644 --- a/docs/api/synopsis.md +++ b/docs/api/synopsis.md @@ -13,7 +13,7 @@ either process type. The basic rule is: if a module is [GUI][gui] or low-level system related, then it should be only available in the main process. You need to be familiar with -the concept of [main process vs. renderer process](../tutorial/quick-start.md#main-and-renderer-processes) +the concept of main process vs. renderer process scripts to be able to use those modules. The main process script is like a normal Node.js script: @@ -43,8 +43,6 @@ extra ability to use node modules if `nodeIntegration` is enabled: ``` -To run your app, read [Run your app](../tutorial/quick-start.md#run-your-application). - ## Destructuring assignment As of 0.37, you can use diff --git a/docs/api/system-preferences.md b/docs/api/system-preferences.md index 20c330460ec83..3ece433368878 100644 --- a/docs/api/system-preferences.md +++ b/docs/api/system-preferences.md @@ -130,6 +130,8 @@ This is necessary for events such as `NSUserDefaultsDidChangeNotification`. * `userInfo` Record * `object` String +Returns `Number` - The ID of this subscription + Same as `subscribeNotification`, but uses `NSWorkspace.sharedWorkspace.notificationCenter`. This is necessary for events such as `NSWorkspaceDidActivateApplicationNotification`. @@ -157,13 +159,13 @@ Same as `unsubscribeNotification`, but removes the subscriber from `NSWorkspace. Add the specified defaults to your application's `NSUserDefaults`. -### `systemPreferences.getUserDefault(key, type)` _macOS_ +### `systemPreferences.getUserDefault(key, type)` _macOS_ * `key` String -* `type` String - Can be `string`, `boolean`, `integer`, `float`, `double`, +* `type` Type - Can be `string`, `boolean`, `integer`, `float`, `double`, `url`, `array` or `dictionary`. -Returns `any` - The value of `key` in `NSUserDefaults`. +Returns [`UserDefaultTypes[Type]`](structures/user-default-types.md) - The value of `key` in `NSUserDefaults`. Some popular `key` and `type`s are: diff --git a/docs/api/touch-bar.md b/docs/api/touch-bar.md index 62afc0e251067..10bf400ab47b0 100644 --- a/docs/api/touch-bar.md +++ b/docs/api/touch-bar.md @@ -1,3 +1,5 @@ +# TouchBar + ## Class: TouchBar > Create TouchBar layouts for native macOS applications diff --git a/docs/api/tray.md b/docs/api/tray.md index 1a6b9cf9a5942..ffa93669b1872 100644 --- a/docs/api/tray.md +++ b/docs/api/tray.md @@ -1,3 +1,5 @@ +# Tray + ## Class: Tray > Add icons and context menus to the system's notification area. diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 43a799836ed76..98188c837e098 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -147,7 +147,8 @@ Returns: * `options` BrowserWindowConstructorOptions - The options which will be used for creating the new [`BrowserWindow`](browser-window.md). * `additionalFeatures` String[] - The non-standard features (features not handled - by Chromium or Electron) given to `window.open()`. + by Chromium or Electron) given to `window.open()`. Deprecated, and will now + always be the empty array `[]`. * `referrer` [Referrer](structures/referrer.md) - The referrer that will be passed to the new window. May or may not result in the `Referer` header being sent, depending on the referrer policy. @@ -202,13 +203,11 @@ Returns: * `frameName` String - Name given to the created window in the `window.open()` call. * `options` BrowserWindowConstructorOptions - The options used to create the - BrowserWindow. They are merged in increasing precedence: options inherited - from the parent, parsed options from the `features` string from - `window.open()`, and options given by + BrowserWindow. They are merged in increasing precedence: parsed options + from the `features` string from `window.open()`, security-related + webPreferences inherited from the parent, and options given by [`webContents.setWindowOpenHandler`](web-contents.md#contentssetwindowopenhandlerhandler). Unrecognized options are not filtered out. - * `additionalFeatures` String[] - The non-standard features (features not - handled Chromium or Electron) _Deprecated_ * `referrer` [Referrer](structures/referrer.md) - The referrer that will be passed to the new window. May or may not result in the `Referer` header being sent, depending on the referrer policy. @@ -375,6 +374,8 @@ win.webContents.on('will-prevent-unload', (event) => { }) ``` +**Note:** This will be emitted for `BrowserViews` but will _not_ be respected - this is because we have chosen not to tie the `BrowserView` lifecycle to its owning BrowserWindow should one exist per the [specification](https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event). + #### Event: 'crashed' _Deprecated_ Returns: @@ -839,59 +840,6 @@ Returns: Emitted when `desktopCapturer.getSources()` is called in the renderer process. Calling `event.preventDefault()` will make it return empty sources. -#### Event: 'remote-require' _Deprecated_ - -Returns: - -* `event` IpcMainEvent -* `moduleName` String - -Emitted when `remote.require()` is called in the renderer process. -Calling `event.preventDefault()` will prevent the module from being returned. -Custom value can be returned by setting `event.returnValue`. - -#### Event: 'remote-get-global' _Deprecated_ - -Returns: - -* `event` IpcMainEvent -* `globalName` String - -Emitted when `remote.getGlobal()` is called in the renderer process. -Calling `event.preventDefault()` will prevent the global from being returned. -Custom value can be returned by setting `event.returnValue`. - -#### Event: 'remote-get-builtin' _Deprecated_ - -Returns: - -* `event` IpcMainEvent -* `moduleName` String - -Emitted when `remote.getBuiltin()` is called in the renderer process. -Calling `event.preventDefault()` will prevent the module from being returned. -Custom value can be returned by setting `event.returnValue`. - -#### Event: 'remote-get-current-window' _Deprecated_ - -Returns: - -* `event` IpcMainEvent - -Emitted when `remote.getCurrentWindow()` is called in the renderer process. -Calling `event.preventDefault()` will prevent the object from being returned. -Custom value can be returned by setting `event.returnValue`. - -#### Event: 'remote-get-current-web-contents' _Deprecated_ - -Returns: - -* `event` IpcMainEvent - -Emitted when `remote.getCurrentWebContents()` is called in the renderer process. -Calling `event.preventDefault()` will prevent the object from being returned. -Custom value can be returned by setting `event.returnValue`. - #### Event: 'preferred-size-changed' Returns: @@ -914,7 +862,7 @@ in `webPreferences`. * `httpReferrer` (String | [Referrer](structures/referrer.md)) (optional) - An HTTP Referrer url. * `userAgent` String (optional) - A user agent originating the request. * `extraHeaders` String (optional) - Extra headers separated by "\n". - * `postData` ([UploadRawData[]](structures/upload-raw-data.md) | [UploadFile[]](structures/upload-file.md)) (optional) + * `postData` ([UploadRawData](structures/upload-raw-data.md) | [UploadFile](structures/upload-file.md))[] (optional) * `baseURLForDataURL` String (optional) - Base url (with trailing path separator) for files to be loaded by the data url. This is needed only if the specified `url` is a data url and needs to load other files. Returns `Promise` - the promise will resolve when the page has finished loading @@ -1184,14 +1132,27 @@ Ignore application menu shortcuts while this web contents is focused. * `url` String - The _resolved_ version of the URL passed to `window.open()`. e.g. opening a window with `window.open('foo')` will yield something like `https://the-origin/the/current/path/foo`. * `frameName` String - Name of the window provided in `window.open()` * `features` String - Comma separated list of window features provided to `window.open()`. + * `disposition` String - Can be `default`, `foreground-tab`, `background-tab`, + `new-window`, `save-to-disk` or `other`. + * `referrer` [Referrer](structures/referrer.md) - The referrer that will be + passed to the new window. May or may not result in the `Referer` header being + sent, depending on the referrer policy. + * `postBody` [PostBody](structures/post-body.md) (optional) - The post data that + will be sent to the new window, along with the appropriate headers that will + be set. If no post data is to be sent, the value will be `null`. Only defined + when the window is being created by a form that set `target=_blank`. + Returns `{action: 'deny'} | {action: 'allow', overrideBrowserWindowOptions?: BrowserWindowConstructorOptions}` - `deny` cancels the creation of the new window. `allow` will allow the new window to be created. Specifying `overrideBrowserWindowOptions` allows customization of the created window. Returning an unrecognized value such as a null, undefined, or an object without a recognized 'action' value will result in a console error and have the same effect as returning `{action: 'deny'}`. -Called before creating a window when `window.open()` is called from the -renderer. See [`window.open()`](window-open.md) for more details and how to use this in conjunction with `did-create-window`. +Called before creating a window a new window is requested by the renderer, e.g. +by `window.open()`, a link with `target="_blank"`, shift+clicking on a link, or +submitting a form with `
`. See +[`window.open()`](window-open.md) for more details and how to use this in +conjunction with `did-create-window`. #### `contents.setAudioMuted(muted)` @@ -1320,8 +1281,7 @@ Inserts `text` to the focused element. * `text` String - Content to be searched, must not be empty. * `options` Object (optional) * `forward` Boolean (optional) - Whether to search forward or backward, defaults to `true`. - * `findNext` Boolean (optional) - Whether the operation is first request or a follow up, - defaults to `false`. + * `findNext` Boolean (optional) - Whether to begin a new text finding session with this request. Should be `true` for initial requests, and `false` for follow-up requests. Defaults to `false`. * `matchCase` Boolean (optional) - Whether search should be case-sensitive, defaults to `false`. @@ -1363,19 +1323,21 @@ Captures a snapshot of the page within `rect`. Omitting `rect` will capture the Returns `Boolean` - Whether this page is being captured. It returns true when the capturer count is large then 0. -#### `contents.incrementCapturerCount([size, stayHidden])` +#### `contents.incrementCapturerCount([size, stayHidden, stayAwake])` * `size` [Size](structures/size.md) (optional) - The preferred size for the capturer. * `stayHidden` Boolean (optional) - Keep the page hidden instead of visible. +* `stayAwake` Boolean (optional) - Keep the system awake instead of allowing it to sleep. Increase the capturer count by one. The page is considered visible when its browser window is hidden and the capturer count is non-zero. If you would like the page to stay hidden, you should ensure that `stayHidden` is set to true. This also affects the Page Visibility API. -#### `contents.decrementCapturerCount([stayHidden])` +#### `contents.decrementCapturerCount([stayHidden, stayAwake])` * `stayHidden` Boolean (optional) - Keep the page in hidden state instead of visible. +* `stayAwake` Boolean (optional) - Keep the system awake instead of allowing it to sleep. Decrease the capturer count by one. The page will be set to hidden or occluded state when its browser window is hidden or occluded and the capturer count reaches zero. If you want to diff --git a/docs/api/web-frame-main.md b/docs/api/web-frame-main.md index c349321a2327b..b0460c1713b27 100644 --- a/docs/api/web-frame-main.md +++ b/docs/api/web-frame-main.md @@ -182,3 +182,9 @@ This is not the same as the OS process ID; to read that use `frame.osProcessId`. An `Integer` representing the unique frame id in the current renderer process. Distinct `WebFrameMain` instances that refer to the same underlying frame will have the same `routingId`. + +#### `frame.visibilityState` _Readonly_ + +A `string` representing the [visibility state](https://developer.mozilla.org/en-US/docs/Web/API/Document/visibilityState) of the frame. + +See also how the [Page Visibility API](browser-window.md#page-visibility) is affected by other Electron APIs. diff --git a/docs/api/web-frame.md b/docs/api/web-frame.md index 9891c5d09ab0c..98fa952c83fbc 100644 --- a/docs/api/web-frame.md +++ b/docs/api/web-frame.md @@ -62,6 +62,11 @@ Sets the maximum and minimum pinch-to-zoom level. > webFrame.setVisualZoomLevelLimits(1, 3) > ``` +> **NOTE**: Visual zoom only applies to pinch-to-zoom behavior. Cmd+/-/0 zoom shortcuts are +> controlled by the 'zoomIn', 'zoomOut', and 'resetZoom' MenuItem roles in the application +> Menu. To disable shortcuts, manually [define the Menu](./menu.md#examples) and omit zoom roles +> from the definition. + ### `webFrame.setSpellCheckProvider(language, provider)` * `language` String diff --git a/docs/api/webview-tag.md b/docs/api/webview-tag.md index 10fbd67bb23cc..478c854fc7a76 100644 --- a/docs/api/webview-tag.md +++ b/docs/api/webview-tag.md @@ -5,7 +5,7 @@ Electron's `webview` tag is based on [Chromium's `webview`][chrome-webview], which is undergoing dramatic architectural changes. This impacts the stability of `webviews`, including rendering, navigation, and event routing. We currently recommend to not -use the `webview` tag and to consider alternatives, like `iframe`, Electron's `BrowserView`, +use the `webview` tag and to consider alternatives, like `iframe`, [Electron's `BrowserView`](browser-view.md), or an architecture that avoids embedded content altogether. ## Enabling @@ -130,15 +130,6 @@ inside the `webview`. All your preloads will load for every iframe, you can use `process.isMainFrame` to determine if you are in the main frame or not. This option is disabled by default in the guest page. -### `enableremotemodule` - -```html - -``` - -A `Boolean`. When this attribute is `false` the guest page in `webview` will not have access -to the [`remote`](remote.md) module. The remote module is unavailable by default. - ### `plugins` ```html @@ -274,7 +265,7 @@ webview.addEventListener('dom-ready', () => { * `httpReferrer` (String | [Referrer](structures/referrer.md)) (optional) - An HTTP Referrer url. * `userAgent` String (optional) - A user agent originating the request. * `extraHeaders` String (optional) - Extra headers separated by "\n" - * `postData` ([UploadRawData[]](structures/upload-raw-data.md) | [UploadFile[]](structures/upload-file.md)) (optional) + * `postData` ([UploadRawData](structures/upload-raw-data.md) | [UploadFile](structures/upload-file.md))[] (optional) * `baseURLForDataURL` String (optional) - Base url (with trailing path separator) for files to be loaded by the data url. This is needed only if the specified `url` is a data url and needs to load other files. Returns `Promise` - The promise will resolve when the page has finished loading @@ -515,8 +506,7 @@ Inserts `text` to the focused element. * `text` String - Content to be searched, must not be empty. * `options` Object (optional) * `forward` Boolean (optional) - Whether to search forward or backward, defaults to `true`. - * `findNext` Boolean (optional) - Whether the operation is first request or a follow up, - defaults to `false`. + * `findNext` Boolean (optional) - Whether to begin a new text finding session with this request. Should be `true` for initial requests, and `false` for follow-up requests. Defaults to `false`. * `matchCase` Boolean (optional) - Whether search should be case-sensitive, defaults to `false`. diff --git a/docs/api/window-open.md b/docs/api/window-open.md index c235deea7925b..7d8bfa262dbfa 100644 --- a/docs/api/window-open.md +++ b/docs/api/window-open.md @@ -6,16 +6,15 @@ untrusted content within a renderer. Windows can be created from the renderer in * clicking on links or submitting forms adorned with `target=_blank` * JavaScript calling `window.open()` -In non-sandboxed renderers, or when `nativeWindowOpen` is false (the default), this results in the creation of a -[`BrowserWindowProxy`](browser-window-proxy.md), a light wrapper around -`BrowserWindow`. +For same-origin content, the new window is created within the same process, +enabling the parent to access the child window directly. This can be very +useful for app sub-windows that act as preference panels, or similar, as the +parent can render to the sub-window directly, as if it were a `div` in the +parent. This is the same behavior as in the browser. -However, when the `sandbox` (or directly, `nativeWindowOpen`) option is set, a -`Window` instance is created, as you'd expect in the browser. For same-origin -content, the new window is created within the same process, enabling the parent -to access the child window directly. This can be very useful for app sub-windows that act -as preference panels, or similar, as the parent can render to the sub-window -directly, as if it were a `div` in the parent. +When `nativeWindowOpen` is set to false, `window.open` instead results in the +creation of a [`BrowserWindowProxy`](browser-window-proxy.md), a light wrapper +around `BrowserWindow`. Electron pairs this native Chrome `Window` with a BrowserWindow under the hood. You can take advantage of all the customization available when creating a @@ -23,9 +22,8 @@ BrowserWindow in the main process by using `webContents.setWindowOpenHandler()` for renderer-created windows. BrowserWindow constructor options are set by, in increasing precedence -order: options inherited from the parent, parsed options -from the `features` string from `window.open()`, security-related webPreferences -inherited from the parent, and options given by +order: parsed options from the `features` string from `window.open()`, +security-related webPreferences inherited from the parent, and options given by [`webContents.setWindowOpenHandler`](web-contents.md#contentssetwindowopenhandlerhandler). Note that `webContents.setWindowOpenHandler` has final say and full privilege because it is invoked in the main process. @@ -64,53 +62,23 @@ window.open('https://github.com', '_blank', 'top=500,left=200,frame=false,nodeIn the parent window. * Non-standard features (that are not handled by Chromium or Electron) given in `features` will be passed to any registered `webContents`'s - `did-create-window` event handler in the `additionalFeatures` argument. + `did-create-window` event handler in the `options` argument. +* `frameName` follows the specification of `windowName` located in the [native documentation](https://developer.mozilla.org/en-US/docs/Web/API/Window/open#parameters). To customize or cancel the creation of the window, you can optionally set an override handler with `webContents.setWindowOpenHandler()` from the main -process. Returning `false` cancels the window, while returning an object sets -the `BrowserWindowConstructorOptions` used when creating the window. Note that -this is more powerful than passing options through the feature string, as the -renderer has more limited privileges in deciding security preferences than the -main process. - -### `BrowserWindowProxy` example - -```javascript - -// main.js -const mainWindow = new BrowserWindow() - -mainWindow.webContents.setWindowOpenHandler(({ url }) => { - if (url.startsWith('https://github.com/')) { - return { action: 'allow' } - } - return { action: 'deny' } -}) - -mainWindow.webContents.on('did-create-window', (childWindow) => { - // For example... - childWindow.webContents('will-navigate', (e) => { - e.preventDefault() - }) -}) -``` - -```javascript -// renderer.js -const windowProxy = window.open('https://github.com/', null, 'minimizable=false') -windowProxy.postMessage('hi', '*') -``` +process. Returning `{ action: 'deny' }` cancels the window. Returning `{ +action: 'allow', overrideBrowserWindowOptions: { ... } }` will allow opening +the window and setting the `BrowserWindowConstructorOptions` to be used when +creating the window. Note that this is more powerful than passing options +through the feature string, as the renderer has more limited privileges in +deciding security preferences than the main process. ### Native `Window` example ```javascript // main.js -const mainWindow = new BrowserWindow({ - webPreferences: { - nativeWindowOpen: true - } -}) +const mainWindow = new BrowserWindow() // In this example, only windows with the `about:blank` url will be created. // All other urls will be blocked. @@ -134,3 +102,33 @@ mainWindow.webContents.setWindowOpenHandler(({ url }) => { const childWindow = window.open('', 'modal') childWindow.document.write('

Hello

') ``` + +### `BrowserWindowProxy` example + +```javascript + +// main.js +const mainWindow = new BrowserWindow({ + webPreferences: { nativeWindowOpen: false } +}) + +mainWindow.webContents.setWindowOpenHandler(({ url }) => { + if (url.startsWith('https://github.com/')) { + return { action: 'allow' } + } + return { action: 'deny' } +}) + +mainWindow.webContents.on('did-create-window', (childWindow) => { + // For example... + childWindow.webContents.on('will-navigate', (e) => { + e.preventDefault() + }) +}) +``` + +```javascript +// renderer.js +const windowProxy = window.open('https://github.com/', null, 'minimizable=false') +windowProxy.postMessage('hi', '*') +``` diff --git a/docs/breaking-changes.md b/docs/breaking-changes.md index f3128cf335189..9913e356025de 100644 --- a/docs/breaking-changes.md +++ b/docs/breaking-changes.md @@ -14,7 +14,22 @@ This document uses the following convention to categorize breaking changes: ## Planned Breaking API Changes (14.0) -### API Changed: `window.(open)` +### Removed: `app.allowRendererProcessReuse` + +The `app.allowRendererProcessReuse` property will be removed as part of our plan to +more closely align with Chromium's process model for security, performance and maintainability. + +For more detailed information see [#18397](https://github.com/electron/electron/issues/18397). + +### Removed: Browser Window Affinity + +The `affinity` option when constructing a new `BrowserWindow` will be removed +as part of our plan to more closely align with Chromium's process model for security, +performance and maintainability. + +For more detailed information see [#18397](https://github.com/electron/electron/issues/18397). + +### API Changed: `window.open()` The optional parameter `frameName` will no longer set the title of the window. This now follows the specification described by the [native documentation](https://developer.mozilla.org/en-US/docs/Web/API/Window/open#parameters) under the corresponding parameter `windowName`. @@ -28,6 +43,63 @@ ensure your code works with this property enabled. It has been enabled by defau You will be affected by this change if you use either `webFrame.executeJavaScript` or `webFrame.executeJavaScriptInIsolatedWorld`. You will need to ensure that values returned by either of those methods are supported by the [Context Bridge API](api/context-bridge.md#parameter--error--return-type-support) as these methods use the same value passing semantics. +### Default Changed: `nativeWindowOpen` defaults to `true` + +Prior to Electron 14, `window.open` was by default shimmed to use +`BrowserWindowProxy`. This meant that `window.open('about:blank')` did not work +to open synchronously scriptable child windows, among other incompatibilities. +`nativeWindowOpen` is no longer experimental, and is now the default. + +See the documentation for [window.open in Electron](api/window-open.md) +for more details. + +### Removed: BrowserWindowConstructorOptions inheriting from parent windows + +Prior to Electron 14, windows opened with `window.open` would inherit +BrowserWindow constructor options such as `transparent` and `resizable` from +their parent window. Beginning with Electron 14, this behavior is removed, and +windows will not inherit any BrowserWindow constructor options from their +parents. + +Instead, explicitly set options for the new window with `setWindowOpenHandler`: + +```js +webContents.setWindowOpenHandler((details) => { + return { + action: 'allow', + overrideBrowserWindowOptions: { + // ... + } + } +}) +``` + +### Removed: `additionalFeatures` + +The deprecated `additionalFeatures` property in the `new-window` and +`did-create-window` events of WebContents has been removed. Since `new-window` +uses positional arguments, the argument is still present, but will always be +the empty array `[]`. (Though note, the `new-window` event itself is +deprecated, and is replaced by `setWindowOpenHandler`.) Bare keys in window +features will now present as keys with the value `true` in the options object. + +```js +// Removed in Electron 14 +// Triggered by window.open('...', '', 'my-key') +webContents.on('did-create-window', (window, details) => { + if (details.additionalFeatures.includes('my-key')) { + // ... + } +}) + +// Replace with +webContents.on('did-create-window', (window, details) => { + if (details.options['my-key']) { + // ... + } +}) +``` + ## Planned Breaking API Changes (13.0) ### API Changed: `session.setPermissionCheckHandler(handler)` @@ -136,6 +208,22 @@ systemPreferences.isHighContrastColorScheme() nativeTheme.shouldUseHighContrastColors ``` +### Deprecated: WebContents `new-window` event + +The `new-window` event of WebContents has been deprecated. It is replaced by [`webContents.setWindowOpenHandler()`](api/web-contents.md#contentssetwindowopenhandlerhandler). + +```js +// Deprecated in Electron 13 +webContents.on('new-window', (event) => { + event.preventDefault() +}) + +// Replace with +webContents.setWindowOpenHandler((details) => { + return { action: 'deny' } +}) +``` + ## Planned Breaking API Changes (12.0) ### Removed: Pepper Flash support @@ -160,6 +248,9 @@ the previous behavior, `contextIsolation: false` must be specified in WebPrefere We [recommend having contextIsolation enabled](https://github.com/electron/electron/blob/master/docs/tutorial/security.md#3-enable-context-isolation-for-remote-content) for the security of your application. +Another implication is that `require()` cannot be used in the renderer process unless +`nodeIntegration` is `true` and `contextIsolation` is `false`. + For more details see: https://github.com/electron/electron/issues/23506 ### Removed: `crashReporter.getCrashesDirectory()` @@ -295,14 +386,6 @@ Setting `{ compress: false }` in `crashReporter.start` is deprecated. Nearly all crash ingestion servers support gzip compression. This option will be removed in a future version of Electron. -### Removed: Browser Window Affinity - -The `affinity` option when constructing a new `BrowserWindow` will be removed -as part of our plan to more closely align with Chromium's process model for security, -performance and maintainability. - -For more detailed information see [#18397](https://github.com/electron/electron/issues/18397). - ### Default Changed: `enableRemoteModule` defaults to `false` In Electron 9, using the remote module without explicitly enabling it via the diff --git a/docs/development/build-instructions-gn.md b/docs/development/build-instructions-gn.md index c194465b4147b..cfea03e8c2e34 100644 --- a/docs/development/build-instructions-gn.md +++ b/docs/development/build-instructions-gn.md @@ -1,6 +1,8 @@ # Build Instructions -Follow the guidelines below for building Electron. +Follow the guidelines below for building **Electron itself**, for the purposes of creating custom Electron binaries. For bundling and distributing your app code with the prebuilt Electron binaries, see the [application distribution][application-distribution] guide. + +[application-distribution]: ../tutorial/application-distribution.md ## Platform prerequisites diff --git a/docs/development/build-instructions-linux.md b/docs/development/build-instructions-linux.md index c014ad784e134..d3aeb85a8ff3e 100644 --- a/docs/development/build-instructions-linux.md +++ b/docs/development/build-instructions-linux.md @@ -1,6 +1,8 @@ # Build Instructions (Linux) -Follow the guidelines below for building Electron on Linux. +Follow the guidelines below for building **Electron itself** on Linux, for the purposes of creating custom Electron binaries. For bundling and distributing your app code with the prebuilt Electron binaries, see the [application distribution][application-distribution] guide. + +[application-distribution]: ../tutorial/application-distribution.md ## Prerequisites diff --git a/docs/development/build-instructions-macos.md b/docs/development/build-instructions-macos.md index 3a150568b2332..0461e78095b56 100644 --- a/docs/development/build-instructions-macos.md +++ b/docs/development/build-instructions-macos.md @@ -1,6 +1,8 @@ # Build Instructions (macOS) -Follow the guidelines below for building Electron on macOS. +Follow the guidelines below for building **Electron itself** on macOS, for the purposes of creating custom Electron binaries. For bundling and distributing your app code with the prebuilt Electron binaries, see the [application distribution][application-distribution] guide. + +[application-distribution]: ../tutorial/application-distribution.md ## Prerequisites diff --git a/docs/development/build-instructions-windows.md b/docs/development/build-instructions-windows.md index 258d88dba2b3a..49e436197d851 100644 --- a/docs/development/build-instructions-windows.md +++ b/docs/development/build-instructions-windows.md @@ -1,6 +1,8 @@ # Build Instructions (Windows) -Follow the guidelines below for building Electron on Windows. +Follow the guidelines below for building **Electron itself** on Windows, for the purposes of creating custom Electron binaries. For bundling and distributing your app code with the prebuilt Electron binaries, see the [application distribution][application-distribution] guide. + +[application-distribution]: ../tutorial/application-distribution.md ## Prerequisites @@ -22,7 +24,7 @@ creating a full distribution since `symstore.exe` is used for creating a symbol store from `.pdb` files. * Different versions of the SDK can be installed side by side. To install the SDK, open Visual Studio Installer, select - `Change` → `Individual Components`, scroll down and select the appropriate + `Modify` → `Individual Components`, scroll down and select the appropriate Windows SDK to install. Another option would be to look at the [Windows SDK and emulator archive](https://developer.microsoft.com/en-us/windows/downloads/sdk-archive) and download the standalone version of the SDK respectively. diff --git a/docs/development/clang-tidy.md b/docs/development/clang-tidy.md index 21210b8f6c7b4..b529d91b889b1 100644 --- a/docs/development/clang-tidy.md +++ b/docs/development/clang-tidy.md @@ -10,12 +10,12 @@ files, you need to have built Electron so that it knows which compiler flags were used. There is one required option for the script `--output-dir`, which tells the script which build directory to pull the compilation information from. A typical usage would be: -`npm run lint:clang-tiy --out-dir ../out/Testing` +`npm run lint:clang-tidy --out-dir ../out/Testing` With no filenames provided, all C/C++/Objective-C files will be checked. You can provide a list of files to be checked by passing the filenames after the options: -`npm run lint:clang-tiy --out-dir ../out/Testing shell/browser/api/electron_api_app.cc` +`npm run lint:clang-tidy --out-dir ../out/Testing shell/browser/api/electron_api_app.cc` While `clang-tidy` has a [long list](https://clang.llvm.org/extra/clang-tidy/checks/list.html) diff --git a/docs/development/coding-style.md b/docs/development/coding-style.md index 324513ff86527..498740061f574 100644 --- a/docs/development/coding-style.md +++ b/docs/development/coding-style.md @@ -25,7 +25,7 @@ You can run `npm run lint` to show any style issues detected by `cpplint` and ## C++ and Python For C++ and Python, we follow Chromium's [Coding -Style](https://www.chromium.org/developers/coding-style). You can use +Style](https://chromium.googlesource.com/chromium/src/+/refs/heads/main/styleguide/styleguide.md). You can use [clang-format](clang-format.md) to format the C++ code automatically. There is also a script `script/cpplint.py` to check whether all files conform. diff --git a/docs/development/issues.md b/docs/development/issues.md index 7478433cdd53a..ec0ad5dc04f36 100644 --- a/docs/development/issues.md +++ b/docs/development/issues.md @@ -33,8 +33,7 @@ contributing, and more. Please use the issue tracker for bugs only! To submit a bug report: When opening a new issue in the [`electron/electron` issue tracker](https://github.com/electron/electron/issues/new/choose), users -will be presented with [a template](https://github.com/electron/electron/blob/master/.github/ISSUE_TEMPLATE/Bug_report.md) -that should be filled in. +will be presented with a template that should be filled in. If you believe that you have found a bug in Electron, please fill out the template to the best of your ability. diff --git a/docs/development/pull-requests.md b/docs/development/pull-requests.md index 6179f46907a32..8486c5cf824e7 100644 --- a/docs/development/pull-requests.md +++ b/docs/development/pull-requests.md @@ -106,7 +106,6 @@ Common prefixes: * perf: A code change that improves performance * refactor: A code change that neither fixes a bug nor adds a feature * style: Changes that do not affect the meaning of the code (linting) -* vendor: Bumping a dependency like libchromiumcontent or node Other things to keep in mind when writing a commit message: diff --git a/docs/development/source-code-directory-structure.md b/docs/development/source-code-directory-structure.md index fffab3d525c10..a7d0105f7dcb6 100644 --- a/docs/development/source-code-directory-structure.md +++ b/docs/development/source-code-directory-structure.md @@ -83,8 +83,6 @@ Electron * **.github** - GitHub-specific config files including issues templates and CODEOWNERS. * **dist** - Temporary directory created by `script/create-dist.py` script when creating a distribution. -* **external_binaries** - Downloaded binaries of third-party frameworks which - do not support building with `gn`. * **node_modules** - Third party node modules used for building. * **npm** - Logic for installation of Electron via npm. * **out** - Temporary output directory of `ninja`. @@ -100,7 +98,4 @@ script/ - The set of all scripts Electron runs for a variety of purposes. └── uploaders/ - Uploads various release-related files during release. ``` -* **tools** - Helper scripts used by GN files. - * Scripts put here should never be invoked by users directly, unlike those in `script`. * **typings** - TypeScript typings for Electron's internal code. -* **vendor** - Source code for some third party dependencies. diff --git a/docs/fiddles/features/drag-and-drop/index.html b/docs/fiddles/features/drag-and-drop/index.html index d451042521a5d..7541c174b86fd 100644 --- a/docs/fiddles/features/drag-and-drop/index.html +++ b/docs/fiddles/features/drag-and-drop/index.html @@ -7,12 +7,9 @@

Hello World!

-

- We are using node , - Chrome , - and Electron . -

- Drag me +

Drag the boxes below to somewhere in your OS (Finder/Explorer, Desktop, etc.) to copy an example markdown file.

+
Drag me - File 1
+
Drag me - File 2
diff --git a/docs/fiddles/features/drag-and-drop/main.js b/docs/fiddles/features/drag-and-drop/main.js index bdc28bbf45000..9ad158beafd5e 100644 --- a/docs/fiddles/features/drag-and-drop/main.js +++ b/docs/fiddles/features/drag-and-drop/main.js @@ -1,21 +1,28 @@ const { app, BrowserWindow, ipcMain, nativeImage, NativeImage } = require('electron') -const fs = require('fs'); -const http = require('http'); +const path = require('path') +const fs = require('fs') +const https = require('https') -function createWindow () { +function createWindow() { const win = new BrowserWindow({ width: 800, height: 600, webPreferences: { - nodeIntegration: true + preload: path.join(__dirname, 'preload.js') } }) win.loadFile('index.html') } -const iconName = 'iconForDragAndDrop.png'; -const icon = fs.createWriteStream(`${process.cwd()}/${iconName}`); -http.get('http://img.icons8.com/ios/452/drag-and-drop.png', (response) => { + +const iconName = path.join(__dirname, 'iconForDragAndDrop.png'); +const icon = fs.createWriteStream(iconName); + +// Create a new file to copy - you can also copy existing files. +fs.writeFileSync(path.join(__dirname, 'drag-and-drop-1.md'), '# First file to test drag and drop') +fs.writeFileSync(path.join(__dirname, 'drag-and-drop-2.md'), '# Second file to test drag and drop') + +https.get('https://img.icons8.com/ios/452/drag-and-drop.png', (response) => { response.pipe(icon); }); @@ -23,8 +30,8 @@ app.whenReady().then(createWindow) ipcMain.on('ondragstart', (event, filePath) => { event.sender.startDrag({ - file: filePath, - icon: `${process.cwd()}/${iconName}` + file: path.join(__dirname, filePath), + icon: iconName, }) }) diff --git a/docs/fiddles/features/drag-and-drop/preload.js b/docs/fiddles/features/drag-and-drop/preload.js new file mode 100644 index 0000000000000..4609e12c75528 --- /dev/null +++ b/docs/fiddles/features/drag-and-drop/preload.js @@ -0,0 +1,8 @@ +const { contextBridge, ipcRenderer } = require('electron') +const path = require('path') + +contextBridge.exposeInMainWorld('electron', { + startDrag: (fileName) => { + ipcRenderer.send('ondragstart', fileName) + } +}) diff --git a/docs/fiddles/features/drag-and-drop/renderer.js b/docs/fiddles/features/drag-and-drop/renderer.js index 33f328e30aedd..b402fa3929258 100644 --- a/docs/fiddles/features/drag-and-drop/renderer.js +++ b/docs/fiddles/features/drag-and-drop/renderer.js @@ -1,9 +1,9 @@ -const { ipcRenderer } = require('electron') -const fs = require('fs') +document.getElementById('drag1').ondragstart = (event) => { + event.preventDefault() + window.electron.startDrag('drag-and-drop-1.md') +} -document.getElementById('drag').ondragstart = (event) => { - const fileName = 'drag-and-drop.md' - fs.writeFileSync(fileName, '# Test drag and drop'); +document.getElementById('drag2').ondragstart = (event) => { event.preventDefault() - ipcRenderer.send('ondragstart', process.cwd() + `/${fileName}`) + window.electron.startDrag('drag-and-drop-2.md') } diff --git a/docs/fiddles/features/keyboard-shortcuts/global/index.html b/docs/fiddles/features/keyboard-shortcuts/global/index.html index a3855d2640d8a..fbe7e6323c996 100644 --- a/docs/fiddles/features/keyboard-shortcuts/global/index.html +++ b/docs/fiddles/features/keyboard-shortcuts/global/index.html @@ -7,10 +7,6 @@

Hello World!

-

- We are using node , - Chrome , - and Electron . -

+

Hit Alt+Ctrl+I on Windows or Opt+Cmd+I on Mac to see a message printed to the console.

diff --git a/docs/fiddles/features/keyboard-shortcuts/global/main.js b/docs/fiddles/features/keyboard-shortcuts/global/main.js index 5b4196f7781ab..24b2d343fbaaa 100644 --- a/docs/fiddles/features/keyboard-shortcuts/global/main.js +++ b/docs/fiddles/features/keyboard-shortcuts/global/main.js @@ -4,9 +4,6 @@ function createWindow () { const win = new BrowserWindow({ width: 800, height: 600, - webPreferences: { - nodeIntegration: true - } }) win.loadFile('index.html') diff --git a/docs/fiddles/features/keyboard-shortcuts/interception-from-main/index.html b/docs/fiddles/features/keyboard-shortcuts/interception-from-main/index.html index 6f9d1abf860a5..ff4540a3c9b2e 100644 --- a/docs/fiddles/features/keyboard-shortcuts/interception-from-main/index.html +++ b/docs/fiddles/features/keyboard-shortcuts/interception-from-main/index.html @@ -7,8 +7,6 @@

Hello World!

- We are using node , - Chrome , - and Electron . +

Hit Ctrl+I to see a message printed to the console.

diff --git a/docs/fiddles/features/keyboard-shortcuts/interception-from-main/main.js b/docs/fiddles/features/keyboard-shortcuts/interception-from-main/main.js index 767e574b11aad..80e4012c812d1 100644 --- a/docs/fiddles/features/keyboard-shortcuts/interception-from-main/main.js +++ b/docs/fiddles/features/keyboard-shortcuts/interception-from-main/main.js @@ -1,7 +1,7 @@ const { app, BrowserWindow } = require('electron') app.whenReady().then(() => { - const win = new BrowserWindow({ width: 800, height: 600, webPreferences: { nodeIntegration: true } }) + const win = new BrowserWindow({ width: 800, height: 600 }) win.loadFile('index.html') win.webContents.on('before-input-event', (event, input) => { diff --git a/docs/fiddles/features/keyboard-shortcuts/local/index.html b/docs/fiddles/features/keyboard-shortcuts/local/index.html index a3855d2640d8a..3aeae635b41d2 100644 --- a/docs/fiddles/features/keyboard-shortcuts/local/index.html +++ b/docs/fiddles/features/keyboard-shortcuts/local/index.html @@ -7,10 +7,6 @@

Hello World!

-

- We are using node , - Chrome , - and Electron . -

+

Hit Alt+Shift+I on Windows, or Opt+Cmd+I on mac to see a message printed to the console.

diff --git a/docs/fiddles/features/keyboard-shortcuts/local/main.js b/docs/fiddles/features/keyboard-shortcuts/local/main.js index d4c5006ef7ee0..c583469df4820 100644 --- a/docs/fiddles/features/keyboard-shortcuts/local/main.js +++ b/docs/fiddles/features/keyboard-shortcuts/local/main.js @@ -4,9 +4,6 @@ function createWindow () { const win = new BrowserWindow({ width: 800, height: 600, - webPreferences: { - nodeIntegration: true - } }) win.loadFile('index.html') diff --git a/docs/fiddles/features/keyboard-shortcuts/web-apis/index.html b/docs/fiddles/features/keyboard-shortcuts/web-apis/index.html new file mode 100644 index 0000000000000..b19f3e92fd070 --- /dev/null +++ b/docs/fiddles/features/keyboard-shortcuts/web-apis/index.html @@ -0,0 +1,17 @@ + + + + + + + + Hello World! + + +

Hello World!

+ +

Hit any key with this window focused to see it captured here.

+
Last Key Pressed:
+ + + diff --git a/docs/fiddles/features/keyboard-shortcuts/web-apis/main.js b/docs/fiddles/features/keyboard-shortcuts/web-apis/main.js new file mode 100644 index 0000000000000..5944f55c83f15 --- /dev/null +++ b/docs/fiddles/features/keyboard-shortcuts/web-apis/main.js @@ -0,0 +1,35 @@ +// Modules to control application life and create native browser window +const {app, BrowserWindow} = require('electron') +const path = require('path') + +function createWindow () { + // Create the browser window. + const mainWindow = new BrowserWindow({ + width: 800, + height: 600, + }) + + // and load the index.html of the app. + mainWindow.loadFile('index.html') + +} + +// This method will be called when Electron has finished +// initialization and is ready to create browser windows. +// Some APIs can only be used after this event occurs. +app.whenReady().then(() => { + createWindow() + + app.on('activate', function () { + // On macOS it's common to re-create a window in the app when the + // dock icon is clicked and there are no other windows open. + if (BrowserWindow.getAllWindows().length === 0) createWindow() + }) +}) + +// Quit when all windows are closed, except on macOS. There, it's common +// for applications and their menu bar to stay active until the user quits +// explicitly with Cmd + Q. +app.on('window-all-closed', function () { + if (process.platform !== 'darwin') app.quit() +}) diff --git a/docs/fiddles/features/keyboard-shortcuts/web-apis/renderer.js b/docs/fiddles/features/keyboard-shortcuts/web-apis/renderer.js new file mode 100644 index 0000000000000..7f7e406c4b2cc --- /dev/null +++ b/docs/fiddles/features/keyboard-shortcuts/web-apis/renderer.js @@ -0,0 +1,7 @@ +function handleKeyPress (event) { + // You can put code here to handle the keypress. + document.getElementById("last-keypress").innerText = event.key + console.log(`You pressed ${event.key}`) +} + +window.addEventListener('keyup', handleKeyPress, true) diff --git a/docs/fiddles/features/macos-dark-mode/main.js b/docs/fiddles/features/macos-dark-mode/main.js index e74b345d367aa..4f0254e95bd8c 100644 --- a/docs/fiddles/features/macos-dark-mode/main.js +++ b/docs/fiddles/features/macos-dark-mode/main.js @@ -1,11 +1,12 @@ const { app, BrowserWindow, ipcMain, nativeTheme } = require('electron') +const path = require('path') function createWindow () { const win = new BrowserWindow({ width: 800, height: 600, webPreferences: { - nodeIntegration: true + preload: path.join(__dirname, 'preload.js') } }) @@ -25,16 +26,18 @@ function createWindow () { }) } -app.whenReady().then(createWindow) +app.whenReady().then(() => { + createWindow() + + app.on('activate', () => { + if (BrowserWindow.getAllWindows().length === 0) { + createWindow() + } + }) +}) app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit() } }) - -app.on('activate', () => { - if (BrowserWindow.getAllWindows().length === 0) { - createWindow() - } -}) diff --git a/docs/fiddles/features/macos-dark-mode/preload.js b/docs/fiddles/features/macos-dark-mode/preload.js new file mode 100644 index 0000000000000..3def9e06ed8ea --- /dev/null +++ b/docs/fiddles/features/macos-dark-mode/preload.js @@ -0,0 +1,6 @@ +const { contextBridge, ipcRenderer } = require('electron') + +contextBridge.exposeInMainWorld('darkMode', { + toggle: () => ipcRenderer.invoke('dark-mode:toggle'), + system: () => ipcRenderer.invoke('dark-mode:system') +}) diff --git a/docs/fiddles/features/macos-dark-mode/renderer.js b/docs/fiddles/features/macos-dark-mode/renderer.js index 737f19f51cbe1..637f714c22406 100644 --- a/docs/fiddles/features/macos-dark-mode/renderer.js +++ b/docs/fiddles/features/macos-dark-mode/renderer.js @@ -1,11 +1,9 @@ -const { ipcRenderer } = require('electron') - document.getElementById('toggle-dark-mode').addEventListener('click', async () => { - const isDarkMode = await ipcRenderer.invoke('dark-mode:toggle') + const isDarkMode = await window.darkMode.toggle() document.getElementById('theme-source').innerHTML = isDarkMode ? 'Dark' : 'Light' }) document.getElementById('reset-to-system').addEventListener('click', async () => { - await ipcRenderer.invoke('dark-mode:system') + await window.darkMode.system() document.getElementById('theme-source').innerHTML = 'System' }) diff --git a/docs/fiddles/features/macos-dock-menu/index.html b/docs/fiddles/features/macos-dock-menu/index.html index a3855d2640d8a..02eb6e015a9c6 100644 --- a/docs/fiddles/features/macos-dock-menu/index.html +++ b/docs/fiddles/features/macos-dock-menu/index.html @@ -7,10 +7,6 @@

Hello World!

-

- We are using node , - Chrome , - and Electron . -

+

Right click the dock icon to see the custom menu options.

diff --git a/docs/fiddles/features/macos-dock-menu/main.js b/docs/fiddles/features/macos-dock-menu/main.js index f57caf628cf65..f7f86a2361a80 100644 --- a/docs/fiddles/features/macos-dock-menu/main.js +++ b/docs/fiddles/features/macos-dock-menu/main.js @@ -4,9 +4,6 @@ function createWindow () { const win = new BrowserWindow({ width: 800, height: 600, - webPreferences: { - nodeIntegration: true - } }) win.loadFile('index.html') @@ -27,7 +24,9 @@ const dockMenu = Menu.buildFromTemplate([ ]) app.whenReady().then(() => { - app.dock.setMenu(dockMenu) + if (process.platform === 'darwin') { + app.dock.setMenu(dockMenu) + } }).then(createWindow) app.on('window-all-closed', () => { diff --git a/docs/fiddles/features/notifications/main/index.html b/docs/fiddles/features/notifications/main/index.html index a3855d2640d8a..3c23f9066d9c1 100644 --- a/docs/fiddles/features/notifications/main/index.html +++ b/docs/fiddles/features/notifications/main/index.html @@ -7,10 +7,6 @@

Hello World!

-

- We are using node , - Chrome , - and Electron . -

+

After launching this application, you should see the system notification.

diff --git a/docs/fiddles/features/notifications/main/main.js b/docs/fiddles/features/notifications/main/main.js index 2f9dec51e70e0..f6e6f867ccc88 100644 --- a/docs/fiddles/features/notifications/main/main.js +++ b/docs/fiddles/features/notifications/main/main.js @@ -3,21 +3,17 @@ const { app, BrowserWindow, Notification } = require('electron') function createWindow () { const win = new BrowserWindow({ width: 800, - height: 600, - webPreferences: { - nodeIntegration: true - } + height: 600 }) win.loadFile('index.html') } +const NOTIFICATION_TITLE = 'Basic Notification' +const NOTIFICATION_BODY = 'Notification from the Main process' + function showNotification () { - const notification = { - title: 'Basic Notification', - body: 'Notification from the Main process' - } - new Notification(notification).show() + new Notification({ title: NOTIFICATION_TITLE, body: NOTIFICATION_BODY }).show() } app.whenReady().then(createWindow).then(showNotification) diff --git a/docs/fiddles/features/offscreen-rendering/index.html b/docs/fiddles/features/offscreen-rendering/index.html deleted file mode 100644 index 0da80aefd88a3..0000000000000 --- a/docs/fiddles/features/offscreen-rendering/index.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - Hello World! - - - -

Hello World!

-

- We are using node , - Chrome , - and Electron . -

- - diff --git a/docs/fiddles/features/offscreen-rendering/main.js b/docs/fiddles/features/offscreen-rendering/main.js index 38bbb991a2d04..10ad35d3d9a80 100644 --- a/docs/fiddles/features/offscreen-rendering/main.js +++ b/docs/fiddles/features/offscreen-rendering/main.js @@ -1,5 +1,6 @@ const { app, BrowserWindow } = require('electron') const fs = require('fs') +const path = require('path') app.disableHardwareAcceleration() @@ -12,7 +13,7 @@ app.whenReady().then(() => { fs.writeFileSync('ex.png', image.toPNG()) }) win.webContents.setFrameRate(60) - console.log(`The screenshot has been successfully saved to ${process.cwd()}/ex.png`) + console.log(`The screenshot has been successfully saved to ${path.join(process.cwd(), 'ex.png')}`) }) app.on('window-all-closed', () => { diff --git a/docs/fiddles/features/online-detection/index.html b/docs/fiddles/features/online-detection/index.html new file mode 100644 index 0000000000000..372e5a963f770 --- /dev/null +++ b/docs/fiddles/features/online-detection/index.html @@ -0,0 +1,13 @@ + + + + + Hello World! + + + +

Connection status:

+ + + + diff --git a/docs/fiddles/features/online-detection/main.js b/docs/fiddles/features/online-detection/main.js new file mode 100644 index 0000000000000..7bc42d7725670 --- /dev/null +++ b/docs/fiddles/features/online-detection/main.js @@ -0,0 +1,26 @@ +const { app, BrowserWindow } = require('electron') + +function createWindow () { + const onlineStatusWindow = new BrowserWindow({ + width: 300, + height: 200 + }) + + onlineStatusWindow.loadFile('index.html') +} + +app.whenReady().then(() => { + createWindow() + + app.on('activate', () => { + if (BrowserWindow.getAllWindows().length === 0) { + createWindow() + } + }) +}) + +app.on('window-all-closed', () => { + if (process.platform !== 'darwin') { + app.quit() + } +}) diff --git a/docs/fiddles/features/online-detection/main/index.html b/docs/fiddles/features/online-detection/main/index.html deleted file mode 100644 index 4d6de7642e14d..0000000000000 --- a/docs/fiddles/features/online-detection/main/index.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - Hello World! - - - -

Hello World!

-

- We are using node , - Chrome , - and Electron . -

- - - diff --git a/docs/fiddles/features/online-detection/main/main.js b/docs/fiddles/features/online-detection/main/main.js deleted file mode 100644 index 66066a3a7caf2..0000000000000 --- a/docs/fiddles/features/online-detection/main/main.js +++ /dev/null @@ -1,24 +0,0 @@ -const { app, BrowserWindow, ipcMain } = require('electron') - -let onlineStatusWindow - -app.whenReady().then(() => { - onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false, webPreferences: { nodeIntegration: true } }) - onlineStatusWindow.loadURL(`file://${__dirname}/index.html`) -}) - -ipcMain.on('online-status-changed', (event, status) => { - console.log(status) -}) - -app.on('window-all-closed', () => { - if (process.platform !== 'darwin') { - app.quit() - } -}) - -app.on('activate', () => { - if (BrowserWindow.getAllWindows().length === 0) { - createWindow() - } -}) diff --git a/docs/fiddles/features/online-detection/main/renderer.js b/docs/fiddles/features/online-detection/main/renderer.js deleted file mode 100644 index 0cf53e658669c..0000000000000 --- a/docs/fiddles/features/online-detection/main/renderer.js +++ /dev/null @@ -1,7 +0,0 @@ -const { ipcRenderer } = require('electron') -const updateOnlineStatus = () => { ipcRenderer.send('online-status-changed', navigator.onLine ? 'online' : 'offline') } - -window.addEventListener('online', updateOnlineStatus) -window.addEventListener('offline', updateOnlineStatus) - -updateOnlineStatus() diff --git a/docs/fiddles/features/online-detection/renderer.js b/docs/fiddles/features/online-detection/renderer.js new file mode 100644 index 0000000000000..223a517ae1677 --- /dev/null +++ b/docs/fiddles/features/online-detection/renderer.js @@ -0,0 +1,8 @@ +function onlineStatusIndicator () { + document.getElementById('status').innerHTML = navigator.onLine ? 'online' : 'offline' +} + +window.addEventListener('online', onlineStatusIndicator) +window.addEventListener('offline', onlineStatusIndicator) + +onlineStatusIndicator() diff --git a/docs/fiddles/features/online-detection/renderer/index.html b/docs/fiddles/features/online-detection/renderer/index.html deleted file mode 100644 index 4d6de7642e14d..0000000000000 --- a/docs/fiddles/features/online-detection/renderer/index.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - Hello World! - - - -

Hello World!

-

- We are using node , - Chrome , - and Electron . -

- - - diff --git a/docs/fiddles/features/online-detection/renderer/main.js b/docs/fiddles/features/online-detection/renderer/main.js deleted file mode 100644 index 0c5ff987b5b80..0000000000000 --- a/docs/fiddles/features/online-detection/renderer/main.js +++ /dev/null @@ -1,20 +0,0 @@ -const { app, BrowserWindow } = require('electron') - -let onlineStatusWindow - -app.whenReady().then(() => { - onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false }) - onlineStatusWindow.loadURL(`file://${__dirname}/index.html`) -}) - -app.on('window-all-closed', () => { - if (process.platform !== 'darwin') { - app.quit() - } -}) - -app.on('activate', () => { - if (BrowserWindow.getAllWindows().length === 0) { - createWindow() - } -}) diff --git a/docs/fiddles/features/online-detection/renderer/renderer.js b/docs/fiddles/features/online-detection/renderer/renderer.js deleted file mode 100644 index 724b6c36bc9fa..0000000000000 --- a/docs/fiddles/features/online-detection/renderer/renderer.js +++ /dev/null @@ -1,6 +0,0 @@ -const alertOnlineStatus = () => { window.alert(navigator.onLine ? 'online' : 'offline') } - -window.addEventListener('online', alertOnlineStatus) -window.addEventListener('offline', alertOnlineStatus) - -alertOnlineStatus() diff --git a/docs/fiddles/features/progress-bar/index.html b/docs/fiddles/features/progress-bar/index.html index a3855d2640d8a..d68c5129a6c2b 100644 --- a/docs/fiddles/features/progress-bar/index.html +++ b/docs/fiddles/features/progress-bar/index.html @@ -7,10 +7,9 @@

Hello World!

-

- We are using node , - Chrome , - and Electron . -

+

Keep an eye on the dock (Mac) or taskbar (Windows, Unity) for this application!

+

It should indicate a progress that advances from 0 to 100%.

+

It should then show indeterminate (Windows) or pin at 100% (other operating systems) + briefly and then loop.

diff --git a/docs/fiddles/features/progress-bar/main.js b/docs/fiddles/features/progress-bar/main.js index a53bf6b9856f0..c400638359011 100644 --- a/docs/fiddles/features/progress-bar/main.js +++ b/docs/fiddles/features/progress-bar/main.js @@ -1,21 +1,39 @@ const { app, BrowserWindow } = require('electron') +let progressInterval + function createWindow () { const win = new BrowserWindow({ width: 800, - height: 600, - webPreferences: { - nodeIntegration: true - } + height: 600 }) win.loadFile('index.html') - win.setProgressBar(0.5) -} + const INCREMENT = 0.03 + const INTERVAL_DELAY = 100 // ms + + let c = 0 + progressInterval = setInterval(() => { + // update progress bar to next value + // values between 0 and 1 will show progress, >1 will show indeterminate or stick at 100% + win.setProgressBar(c) + + // increment or reset progress bar + if (c < 2) { + c += INCREMENT + } else { + c = (-INCREMENT * 5) // reset to a bit less than 0 to show reset state + } + }, INTERVAL_DELAY) +} app.whenReady().then(createWindow) +// before the app is terminated, clear both timers +app.on('before-quit', () => { + clearInterval(progressInterval) +}) app.on('window-all-closed', () => { if (process.platform !== 'darwin') { diff --git a/docs/fiddles/quick-start/index.html b/docs/fiddles/quick-start/index.html index a3855d2640d8a..f008d867a0f89 100644 --- a/docs/fiddles/quick-start/index.html +++ b/docs/fiddles/quick-start/index.html @@ -8,9 +8,9 @@

Hello World!

- We are using node , - Chrome , - and Electron . + We are using Node.js , + Chromium , + and Electron .

diff --git a/docs/fiddles/quick-start/main.js b/docs/fiddles/quick-start/main.js index bfc856e606355..519a67947cdbb 100644 --- a/docs/fiddles/quick-start/main.js +++ b/docs/fiddles/quick-start/main.js @@ -1,19 +1,27 @@ const { app, BrowserWindow } = require('electron') +const path = require('path') function createWindow () { const win = new BrowserWindow({ width: 800, height: 600, webPreferences: { - nodeIntegration: true, - contextIsolation: false + preload: path.join(__dirname, 'preload.js') } }) win.loadFile('index.html') } -app.whenReady().then(createWindow) +app.whenReady().then(() => { + createWindow() + + app.on('activate', () => { + if (BrowserWindow.getAllWindows().length === 0) { + createWindow() + } + }) +}) app.on('window-all-closed', () => { if (process.platform !== 'darwin') { @@ -21,8 +29,3 @@ app.on('window-all-closed', () => { } }) -app.on('activate', () => { - if (BrowserWindow.getAllWindows().length === 0) { - createWindow() - } -}) diff --git a/docs/fiddles/quick-start/preload.js b/docs/fiddles/quick-start/preload.js new file mode 100644 index 0000000000000..7674d012240c4 --- /dev/null +++ b/docs/fiddles/quick-start/preload.js @@ -0,0 +1,11 @@ +window.addEventListener('DOMContentLoaded', () => { + const replaceText = (selector, text) => { + const element = document.getElementById(selector) + if (element) element.innerText = text + } + + for (const type of ['chrome', 'node', 'electron']) { + replaceText(`${type}-version`, process.versions[type]) + } +}) + diff --git a/docs/images/chrome-processes.png b/docs/images/chrome-processes.png new file mode 100644 index 0000000000000..1b0a1c0060f95 Binary files /dev/null and b/docs/images/chrome-processes.png differ diff --git a/docs/images/connection-status.png b/docs/images/connection-status.png new file mode 100644 index 0000000000000..6dcf2574e86a0 Binary files /dev/null and b/docs/images/connection-status.png differ diff --git a/docs/styleguide.md b/docs/styleguide.md index cd912cafb43a0..e1601a16fa589 100644 --- a/docs/styleguide.md +++ b/docs/styleguide.md @@ -2,15 +2,14 @@ These are the guidelines for writing Electron documentation. -## Titles +## Headings * Each page must have a single `#`-level title at the top. -* Chapters in the same page must have `##`-level titles. -* Sub-chapters need to increase the number of `#` in the title according to +* Chapters in the same page must have `##`-level headings. +* Sub-chapters need to increase the number of `#` in the heading according to their nesting depth. -* All words in the page's title must be capitalized, except for conjunctions - like "of" and "and" . -* Only the first word of a chapter title must be capitalized. +* The page's title must follow [APA title case][title-case]. +* All chapters must follow [APA sentence case][sentence-case]. Using `Quick Start` as example: @@ -44,12 +43,20 @@ For API references, there are exceptions to this rule. ## Markdown rules +This repository uses the [`markdownlint`][markdownlint] package to enforce consistent +Markdown styling. For the exact rules, see the `.markdownlint.json` file in the root +folder. + +There are a few style guidelines that aren't covered by the linter rules: + + * Use `sh` instead of `cmd` in code blocks (due to the syntax highlighter). -* Lines should be wrapped at 80 columns. +* Keep line lengths between 80 and 100 characters if possible for readability + purposes. * No nesting lists more than 2 levels (due to the markdown renderer). * All `js` and `javascript` code blocks are linted with [standard-markdown](https://www.npmjs.com/package/standard-markdown). -* For unordered lists, use asterisks instead of dashes +* For unordered lists, use asterisks instead of dashes. ## Picking words @@ -60,14 +67,15 @@ For API references, there are exceptions to this rule. The following rules only apply to the documentation of APIs. -### Page title +### Title and description -Each page must use the actual object name returned by `require('electron')` -as the title, such as `BrowserWindow`, `autoUpdater`, and `session`. +Each module's API doc must use the actual object name returned by `require('electron')` +as its title (such as `BrowserWindow`, `autoUpdater`, and `session`). -Under the page title must be a one-line description starting with `>`. +Directly under the page title, add a one-line description of the module +as a markdown quote (beginning with `>`). -Using `session` as example: +Using the `session` module as an example: ```markdown # session @@ -99,14 +107,19 @@ Using `autoUpdater` as an example: * API classes or classes that are part of modules must be listed under a `## Class: TheClassName` chapter. * One page can have multiple classes. -* Constructors must be listed with `###`-level titles. -* [Static Methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/static) must be listed under a `### Static Methods` chapter. -* [Instance Methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#Prototype_methods) must be listed under an `### Instance Methods` chapter. -* All methods that have a return value must start their description with "Returns `[TYPE]` - Return description" - * If the method returns an `Object`, its structure can be specified using a colon followed by a newline then an unordered list of properties in the same style as function parameters. +* Constructors must be listed with `###`-level headings. +* [Static Methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/static) + must be listed under a `### Static Methods` chapter. +* [Instance Methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#Prototype_methods) + must be listed under an `### Instance Methods` chapter. +* All methods that have a return value must start their description with + "Returns `[TYPE]` - [Return description]" + * If the method returns an `Object`, its structure can be specified using a colon + followed by a newline then an unordered list of properties in the same style as + function parameters. * Instance Events must be listed under an `### Instance Events` chapter. * Instance Properties must be listed under an `### Instance Properties` chapter. - * Instance properties must start with "A [Property Type] ..." + * Instance Properties must start with "A [Property Type] ..." Using the `Session` and `Cookies` classes as an example: @@ -142,7 +155,7 @@ Using the `Session` and `Cookies` classes as an example: #### `cookies.get(filter, callback)` ``` -### Methods +### Methods and their arguments The methods chapter must be in the following form: @@ -155,8 +168,12 @@ The methods chapter must be in the following form: ... ``` -The title can be `###` or `####`-levels depending on whether it is a method of -a module or a class. +#### Heading level + +The heading can be `###` or `####`-levels depending on whether the method +belongs to a module or a class. + +#### Function signature For modules, the `objectName` is the module's name. For classes, it must be the name of the instance of the class, and must not be the same as the module's @@ -165,23 +182,33 @@ name. For example, the methods of the `Session` class under the `session` module must use `ses` as the `objectName`. -The optional arguments are notated by square brackets `[]` surrounding the optional argument -as well as the comma required if this optional argument follows another +Optional arguments are notated by square brackets `[]` surrounding the optional +argument as well as the comma required if this optional argument follows another argument: -```sh +```markdown required[, optional] ``` -Below the method is more detailed information on each of the arguments. The type -of argument is notated by either the common types: +#### Argument descriptions -* [`String`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) -* [`Number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) -* [`Object`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) -* [`Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) -* [`Boolean`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean) -* Or a custom type like Electron's [`WebContent`](api/web-contents.md) +More detailed information on each of the arguments is noted in an unordered list +below the method. The type of argument is notated by either JavaScript primitives +(e.g. `String`, `Promise`, or `Object`), a custom API structure like Electron's +[`Cookie`](api/structures/cookie.md), or the wildcard `any`. + +If the argument is of type `Array`, use `[]` shorthand with the type of value +inside the array (for example,`any[]` or `String[]`). + +If the argument is of type `Promise`, parametrize the type with what the promise +resolves to (for example, `Promise` or `Promise`). + +If an argument can be of multiple types, separate the types with `|`. + +The description for `Function` type arguments should make it clear how it may be +called and list the types of the parameters that will be passed to it. + +#### Platform-specific functionality If an argument or a method is unique to certain platforms, those platforms are denoted using a space-delimited italicized list following the datatype. Values @@ -191,12 +218,6 @@ can be `macOS`, `Windows` or `Linux`. * `animate` Boolean (optional) _macOS_ _Windows_ - Animate the thing. ``` -`Array` type arguments must specify what elements the array may include in -the description below. - -The description for `Function` type arguments should make it clear how it may be -called and list the types of the parameters that will be passed to it. - ### Events The events chapter must be in following form: @@ -211,8 +232,8 @@ Returns: ... ``` -The title can be `###` or `####`-levels depending on whether it is an event of -a module or a class. +The heading can be `###` or `####`-levels depending on whether the event +belongs to a module or a class. The arguments of an event follow the same rules as methods. @@ -226,9 +247,13 @@ The properties chapter must be in following form: ... ``` -The title can be `###` or `####`-levels depending on whether it is a property of -a module or a class. +The heading can be `###` or `####`-levels depending on whether the property +belongs to a module or a class. -## Documentation Translations +## Documentation translations See [electron/i18n](https://github.com/electron/i18n#readme) + +[title-case]: https://apastyle.apa.org/style-grammar-guidelines/capitalization/title-case +[sentence-case]: https://apastyle.apa.org/style-grammar-guidelines/capitalization/sentence-case +[markdownlint]: https://github.com/DavidAnson/markdownlint diff --git a/docs/tutorial/application-distribution.md b/docs/tutorial/application-distribution.md index 5bc3a6a67d443..5dd54c629b2a4 100644 --- a/docs/tutorial/application-distribution.md +++ b/docs/tutorial/application-distribution.md @@ -18,7 +18,7 @@ distributable Electron application, such as bundling your application, rebranding the executable, and setting the right icons. You can check the example of how to package your app with `electron-forge` in -our [Quick Start Guide](quick-start.md#package-and-distribute-the-application). +the [Quick Start guide](quick-start.md#package-and-distribute-your-application). ## Manual distribution diff --git a/docs/tutorial/code-signing.md b/docs/tutorial/code-signing.md index d3a3ccbac2861..5d6b16216ea49 100644 --- a/docs/tutorial/code-signing.md +++ b/docs/tutorial/code-signing.md @@ -190,7 +190,6 @@ it may be worth your time to shop around. Popular resellers include: * [digicert](https://www.digicert.com/code-signing/microsoft-authenticode.htm) * [Sectigo](https://sectigo.com/ssl-certificates-tls/code-signing) -* [GoDaddy](https://au.godaddy.com/web-security/code-signing-certificate) * Amongst others, please shop around to find one that suits your needs, Google is your friend 😄 diff --git a/docs/tutorial/dark-mode.md b/docs/tutorial/dark-mode.md index 2bbda10435c73..5ac69241ebae2 100644 --- a/docs/tutorial/dark-mode.md +++ b/docs/tutorial/dark-mode.md @@ -47,18 +47,18 @@ of this theming, due to the use of the macOS 10.14 SDK. ## Example -We'll start with a working application from the -[Quick Start Guide](quick-start.md) and add functionality gradually. +This example demonstrates an Electron application that derives its theme colors from the +`nativeTheme`. Additionally, it provides theme toggle and reset controls using IPC channels. -First, let's edit our interface so users can toggle between light and dark -modes. This basic UI contains buttons to change the `nativeTheme.themeSource` -setting and a text element indicating which `themeSource` value is selected. -By default, Electron follows the system's dark mode preference, so we -will hardcode the theme source as "System". +```javascript fiddle='docs/fiddles/features/macos-dark-mode' -Add the following lines to the `index.html` file: +``` + +### How does this work? -```html +Starting with the `index.html` file: + +```html title='index.html' @@ -80,65 +80,70 @@ Add the following lines to the `index.html` file: ``` -Next, add [event listeners](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener) -that listen for `click` events on the toggle buttons. Because the `nativeTheme` -module only exposed in the Main process, you need to set up each listener's -callback to use IPC to send messages to and handle responses from the Main -process: +And the `style.css` file: + +```css title='style.css' +@media (prefers-color-scheme: dark) { + body { background: #333; color: white; } +} -* when the "Toggle Dark Mode" button is clicked, we send the -`dark-mode:toggle` message (event) to tell the Main process to trigger a theme -change, and update the "Current Theme Source" label in the UI based on the -response from the Main process. -* when the "Reset to System Theme" button is clicked, we send the -`dark-mode:system` message (event) to tell the Main process to use the system -color scheme, and update the "Current Theme Source" label to `System`. +@media (prefers-color-scheme: light) { + body { background: #ddd; color: black; } +} +``` + +The example renders an HTML page with a couple elements. The `` + element shows which theme is currently selected, and the two `