Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Clipboard being undefined in insecure contexts #15

Merged
merged 4 commits into from
Aug 12, 2024
Merged

Handle Clipboard being undefined in insecure contexts #15

merged 4 commits into from
Aug 12, 2024

Conversation

ysangkok
Copy link
Contributor

@ysangkok ysangkok commented Aug 9, 2024

Fixes #14.

@ysangkok
Copy link
Contributor Author

ysangkok commented Aug 9, 2024

I tested this with the following program:

module Test.Main where

import Prelude
import Effect (Effect)
import Effect.Console (log)
import Web.Clipboard (clipboard)
import Data.Maybe (isJust)
import Web.HTML (window)
import Web.HTML.Window (navigator)

main :: Effect Unit
main = do
  clp <- window >>= navigator >>= clipboard
  log $ show $ isJust $ clp

Which I bundled using

spago bundle --platform browser --bundle-type app --module Test.Main --outfile index.js

@garyb
Copy link
Member

garyb commented Aug 9, 2024

Would you mind making one further change? Add an explicit export list that exports everything aside from the clipboardWrapper. Thanks!

@ysangkok
Copy link
Contributor Author

ysangkok commented Aug 9, 2024

@garyb Done

@garyb
Copy link
Member

garyb commented Aug 9, 2024

Sorry, one last minor thing, eslint is complaining because of single rather than double quotes ('undefined') in the JS.

@ysangkok
Copy link
Contributor Author

ysangkok commented Aug 9, 2024

@garyb Added a commit to switch quote style, tested with following eslint.config.mjs configuration:

import globals from "globals";
import pluginJs from "@eslint/js";
import stylisticJs from "@stylistic/eslint-plugin-js"

export default [
  {
    languageOptions: { globals: globals.browser }
    , plugins: {"@stylistic/js": stylisticJs}
    , rules:
        {
          "@stylistic/js/indent": ["warn", 2]
          , "@stylistic/js/quotes": ["warn", "double"]
        }
  },
  pluginJs.configs.recommended,
];

@garyb
Copy link
Member

garyb commented Aug 12, 2024

Thanks!

@garyb garyb merged commit 144f99f into purescript-web:master Aug 12, 2024
1 check passed
@ysangkok ysangkok deleted the secure-context branch August 12, 2024 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Types don't reflect that clipboard is undefined in insecure contexts
2 participants