document beforeWrite